我通过PHP / cURL获取XML String并希望将其用作simplexml obejct但它是空的。 代码:
$result = curl_exec($ch);
echo 'RESULT VAR:<br>';
echo htmlentities($result).'<br><br>';
$xml = simplexml_load_string($result);
echo 'OUTPUT of xml->InsertObservationResponse->AssignedObservationId: <br>';
echo "ID: ".($xml->InsertObservationResponse->AssignedObservationId).'<br>';
生成此输出:
RESULT VAR:
<?xml version="1.0" encoding="UTF-8"?> <sos:InsertObservationResponse xmlns:sos="http://www.opengis.net/sos/1.0"> <sos:AssignedObservationId>o_1626</sos:AssignedObservationId> </sos:InsertObservationResponse>
OUTPUT of xml->InsertObservationResponse->AssignedObservationId:
ID:
我想输出的内容:
RESULT VAR:
<?xml version="1.0" encoding="UTF-8"?> <sos:InsertObservationResponse xmlns:sos="http://www.opengis.net/sos/1.0"> <sos:AssignedObservationId>o_1626</sos:AssignedObservationId> </sos:InsertObservationResponse>
OUTPUT of xml->InsertObservationResponse->AssignedObservationId:
ID: o_1626
我还使用https://github.com/IMSoP/simplexml_debug中的simplexml调试库 和
simplexml_dump($xml);
打印:
SimpleXML object (1 item) [ Element { Namespace: 'http://www.opengis.net/sos/1.0' Namespace Alias: 'sos' Name: 'InsertObservationResponse' String Content: ' ' Content in Namespace sos Namespace URI: 'http://www.opengis.net/sos/1.0' Children: 1 - 1 'AssignedObservationId' Attributes: 0 } ]
谢谢