0

Possible Duplicate:
PHP namespace simplexml problems

i am fetching an XML String via PHP/cURL and want to use it as a simplexml obejct but it's empty. Code:

$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>';

Produces this output:

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: 

What I want to output:

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

I also use the simplexml debug lib from https://github.com/IMSoP/simplexml_debug and

simplexml_dump($xml);

prints:

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 } ] 

Thank you

Community
  • 1
  • 1
vo1d
  • 2,723
  • 2
  • 20
  • 17

1 Answers1

0

You can use children like this:

$xml->children('sos', true)->AssignedObservationId;
subroutines
  • 1,458
  • 1
  • 12
  • 16