最近幾天我試圖解析soap響應(通過curl命令行),但我無法讓它工作。我只想得到ResourceIdentifier
的對象值,即rs-1304500829200-200。我使用PHP 5.3.x如何在PHP中解析SOAP響應
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:deliverMDRecordsResponse xmlns:ns2="http://mdstore.data.dnetlib.eu/" xmlns:ns3="http://www.w3.org/2005/08/addressing">
<return>
<ns3:Address>http://129.70.12.20:8282/dnet-mdstore/services/MDStoreResultSet</ns3:Address>
<ns3:ReferenceParameters>
<ResourceIdentifier:ResourceIdentifier xmlns:ResourceIdentifier="http://www.driver.org" xmlns:wsa="http://www.w3.org/2005/08/addressing">rs-1304500829200-200</ResourceIdentifier:ResourceIdentifier>
</ns3:ReferenceParameters>
</return>
</ns2:deliverMDRecordsResponse>
</soap:Body>
</soap:Envelope>
<?
$response=<<<END ....soap response here... END;
$xml = simplexml_load_string($source);
$xml->registerXPathNamespace('t', 'http://www.driver.org');
foreach ($xml->xpath('//t:ResourceIdentifier') as $item)
{ // print_r($item);
echo $item->asXML();
}
?>
請參閱:http://stackoverflow.com/editing-help – Treffynnon 2011-05-04 11:54:54
「print_r」的輸出是什麼? – 2011-05-04 11:55:46
爲什麼選擇CURL而不是http://www.php.net/manual/en/book.soap.php? – Treffynnon 2011-05-04 11:56:40