从php中读取SOAP XML
您好,我从soap服务获得了这个xml。我使用curl获取xml。 如何在php中访问节点?结果可以有更多的结果集从php中读取SOAP XML,php,xml,soap,Php,Xml,Soap,您好,我从soap服务获得了这个xml。我使用curl获取xml。 如何在php中访问节点?结果可以有更多的结果集 <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <ns3:ExampleResponse xmlns:ns3="http://example.com/ptfall" xml
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns3:ExampleResponse xmlns:ns3="http://example.com/ptfall" xmlns:ns2="http://example.com/soa">
<return>
<ns3:resultSet>
<ns3:categoria>
<ns2:codice>1</ns2:codice>
<ns2:descrizione>Esempio xxx</ns2:descrizione>
</ns3:categoria>
<ns3:causale>
<ns3:codice>_XXXXX</ns3:codice>
<ns3:descrizione>Annullo Mancato</ns3:descrizione>
<ns3:identificativo>
<ns2:long>74</ns2:long>
</ns3:identificativo>
</ns3:causale>
</ns3:resultSet>
<ns3:serviceInfo>
<ns2:codiceErroreOccorso>0</ns2:codiceErroreOccorso>
<ns2:erroreOccorso>false</ns2:erroreOccorso>
<ns2:executionId>xxxxxxxxxxx</ns2:executionId>
<ns2:tipoErroreOccorso>0</ns2:tipoErroreOccorso>
</ns3:serviceInfo>
</return>
</ns3:ExampleResponse>
</soap:Body>
</soap:Envelope>
它比这稍微复杂一点,但是,对于您的
ns3:descripione
,可以这样做:
$soap = simplexml_load_string($data);
$soap->registerXPathNamespace("ns3", "http://example.com/ptfall");
$resultSet = $soap->xpath('//ns3:resultSet');
foreach ($resultSet as $rs)
{
$infos = $rs->xpath('.//*[local-name()="descrizione"]/text()');
foreach ($infos as $target) {
echo $target ."\r\n";
}
}
输出:
Esempio xxx
Annullo Mancato
您可以使用
DOMDocument()
在XMLwow works中解析您的响应!谢谢lot@MarcoBozzola很高兴它对你有用!
Esempio xxx
Annullo Mancato