I'm using simplexml_load_string to load some XML:
$xml = "<payment><cardHolderName><![CDATA[John Smith]]></cardHolderName></payment>";
$xml = simplexml_load_string($xml, null, LIBXML_NOCDATA);
How can I then access the cardHolderName (John Smith) using xpath? I've tried:
$name = $xml->xpath('/payment/cardHolderName');
echo $name;
But the value is empty and I get a warning:
Array to string conversion
Same result with all of these xpaths:
'/payment/cardHolderName'
'/payment/cardHolderName[1]'
'/payment/cardHolderName/text()'
'/payment/cardHolderName[1]/text()'
Thanks in advance.
SimpleXMLElement::xpath()has no support for the xpath functiontext(). You can only query elements and attributes with simplexml xpath.