重複の可能性:
PHP 名前空間 simplexml の問題
PHP/cURL 経由で XML 文字列を取得していて、それを simplexml オブジェクトとして使用したいのですが、空です。コード:
$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 } ]
ありがとうございました