I am a complete Python noob
既然铺垫已经完成,我正试图从SOAP响应中解析一些信息。
回复正文如下:
<soap:Body>
<ProcessMessageResponse xmlns="http://www.starstandards.org/webservices/2005/10/transport">
<payload>
<content id="Content0">
<CustomerLookupResponse xmlns="">
<Customer>
<CompanyNumber>ZQ1</CompanyNumber>
<CustomerNumber>1051012</CustomerNumber>
<TypeCode>I</TypeCode>
<LastName>NAME</LastName>
<FirstName>BASIC</FirstName>
<MiddleName/>
<Salutation/>
<Gender/>
<Language/>
<Address1/>
<Address2/>
<Address3/>
<City/>
<County/>
<StateCode/>
<ZipCode>0</ZipCode>
<PhoneNumber>0</PhoneNumber>
<BusinessPhone>0</BusinessPhone>
<BusinessExt>0</BusinessExt>
<FaxNumber>0</FaxNumber>
<BirthDate>0</BirthDate>
<DriversLicense/>
<Contact/>
<PreferredContact/>
<MailCode/>
<TaxExmptNumber/>
<AssignedSalesperson/>
<CustomerType/>
<PreferredPhone/>
<CellPhone>0</CellPhone>
<PagePhone>0</PagePhone>
<OtherPhone>0</OtherPhone>
<OtherPhoneDesc/>
<Email1/>
<Email2/>
<OptionalField/>
<AllowContactByPostal/>
<AllowContactByPhone/>
<AllowContactByEmail/>
<BusinessPhoneExtension/>
<InternationalBusinessPhone/>
<InternationalCellPhone/>
<ExternalCrossReferenceKey>0</ExternalCrossReferenceKey>
<InternationalFaxNumber/>
<InternationalOtherPhone/>
<InternationalHomePhone/>
<CustomerPreferredName/>
<InternationalPagerPhone/>
<PreferredLanguage/>
<LastChangeDate>20130401</LastChangeDate>
<Vehicles/>
<CCID/>
<CCCD>0</CCCD>
</Customer>
</CustomerLookupResponse>
</content>
</payload>
</ProcessMessageResponse>
</soap:Body>
我有下面的代码片段来展示我如何解析出我想要的响应:
^{pr2}$我不确定我为什么得到' ', ' ', ' ', <xml response>...
的输出
看起来您过度指定了字段名,因此它们不匹配任何内容,因此您的
for customer in ...
永远不会运行。试试这个:另外,全局变量名通常是邪恶的;我想您之所以添加它们是因为遇到了“variable not defined”错误?这应该是for循环实际上没有运行的线索。在
你可以利用xml.dom.minidom公司名称:
注意,对于输入文件,肥皂.xml: 1我添加了xml版本/soap:信封元素围绕您提供的XML,否则它将无法解析 2我添加了另一个Customer元素来测试我的代码
输出:
^{pr2}$相关问题 更多 >
编程相关推荐