PHP unable to access Xpath node of a SimpleXMLElement Object




$x = new DomDocument();
$x->loadXML($responseXml);
$xml = simplexml_import_dom($x);


Outputting the array using print_r($xml) gives the following:



SimpleXMLElement Object
(
[Timestamp] => 2014-11-09T18:28:47.843Z
[Ack] => Success
[Version] => 897
[Build] => E897_UNI_API5_17253832_R1
[Store] => SimpleXMLElement Object
(
[Name] => test
[SubscriptionLevel] => Basic
[Description] => Welcome Message.
)

)


Using $xml->Store->Description outputs "Welcome Message."


When I use xpath to return the Description node using the following code, I get an empty array:



$xpath = new DOMXPath($x);
$result = $xpath->query("/Store/Description");


Why does this fail?


No comments:

Post a Comment