我必须解析此xml并检索Username
和Password
值。
<?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">
<soap:Body>
<ProcessResponse
xmlns="http://api.securecrmsite.com/">
<ProcessResult>
<RequestID>5666290</RequestID>
<PrimaryKeyID>0</PrimaryKeyID>
<Success>true</Success>
<Message>Process completed. Found 1 records.</Message>
<Records>1</Records>
<ProcessData>
<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:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Results">
<xs:complexType>
<xs:sequence>
<xs:element name="CustomerID" type="xs:int" minOccurs="0" />
<xs:element name="Username" type="xs:string" minOccurs="0" />
<xs:element name="Password" 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="">
<Results diffgr:id="Results1" msdata:rowOrder="0">
<CustomerID>2465266</CustomerID>
<Username>tamimanother1</Username>
<Password>4565AA</Password>
</Results>
</NewDataSet>
</diffgr:diffgram>
</ProcessData>
<XmlRequest>&lt;soap:Envelope
xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;
xmlns:soap=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;&lt;soap:Body&gt;&lt;Process
xmlns=&quot;http://api.securecrmsite.com/&quot;&gt;&lt;Credentials&gt;&lt;CompanyKey&gt;3785&lt;/CompanyKey&gt;&lt;APIKey&gt;7ca9d84b-e7c9-4d19-aae1-218d109eab6f&lt;/APIKey&gt;&lt;/Credentials&gt;&lt;ProcessName&gt;CustomerInsert&lt;/ProcessName&gt;&lt;Parameters&gt;&lt;ApiParams&gt;&lt;Name&gt;FirstName&lt;/Name&gt;&lt;Value&gt;tamim&lt;/Value&gt;&lt;/ApiParams&gt;&lt;ApiParams&gt;&lt;Name&gt;LastName&lt;/Name&gt;&lt;Value&gt;another&lt;/Value&gt;&lt;/ApiParams&gt;&lt;ApiParams&gt;&lt;Name&gt;Email&lt;/Name&gt;&lt;Value&gt;test@test.com&lt;/Value&gt;&lt;/ApiParams&gt;&lt;/Parameters&gt;&lt;/Process&gt;&lt;/soap:Body&gt;&lt;/soap:Envelope&gt;
</XmlRequest>
</ProcessResult>
</ProcessResponse>
</soap:Body>
</soap:Envelope>
我试过这个 - &gt;
```
$xml = str_ireplace(['SOAP-ENV:', 'SOAP:'], '', $xml);
$data = simplexml_load_string($xml);
print_r($data->Body->ProcessResponse->NewDataSet);
```
答案 0 :(得分:0)
如果你想要xpath,那就试试这个
concat(//Results/Username,"|",//Results/Password)
结果String='tamimanother1|4565AA'