0

可能重复:
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 } ] 

谢谢

4

1 回答 1

0

你可以像这样使用孩子

$xml->children('sos', true)->AssignedObservationId;
于 2012-11-26T01:11:28.970 回答