【发布时间】:2017-10-05 22:52:25
【问题描述】:
我收到来自 Web 服务的以下响应。我需要获取 dtAccData (FULL_NAME, GLOBAL_ID) 中的值
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<strGetCustomerValidationResponse xmlns="http://tempuri.org/">
<strGetCustomerValidationResult>21^Please complete your pending form^150675^1</strGetCustomerValidationResult>
<dtAccData>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="Table" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Table">
<xs:complexType>
<xs:sequence>
<xs:element name="FULL_NAME" type="xs:string" minOccurs="0" />
<xs:element name="GLOBAL_ID" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<NewDataSet xmlns="">
<Table diffgr:id="Table1" msdata:rowOrder="0">
<FULL_NAME>TEST39</FULL_NAME>
<GLOBAL_ID>37405-9879863-7</GLOBAL_ID>
</Table>
</NewDataSet>
</diffgr:diffgram>
</dtAccData>
</strGetCustomerValidationResponse>
</soap:Envelope>
如果我加载到简单的 XML 对象并转储,我看不到 dtAccData 中的任何值。我只在下面。
$xml = new SimpleXMLElement($xml_tring);
var_dump($xml);
我明白了
GetCustomerValidationResponse"]=> object(SimpleXMLElement)#2 (2) { ["strGetCustomerValidationResult"]=> string(45) "21^Please complete your pending form^630160^1" ["dtAccData"]=> object(SimpleXMLElement)#3 (0) { } } }
我该怎么办。
【问题讨论】:
-
你为什么不使用 SOAP 扩展?
-
@ThW 我不知道可以使用 SOAP 扩展解析 XML。你能发布一个示例代码吗?
-
你的例子不仅仅是 XML,它是 SOAP。 SOAP 使用 XML 作为基本格式/语法。 PHP 有一个扩展:php.net/soap
-
@ThW 是的,我知道,但是 SOAP 扩展没有任何方法来解析收到的结果 XML。
标签: php xml web-services domdocument