我simplexml_load_string
用来加载一些 XML:
$xml = "<payment><cardHolderName><![CDATA[John Smith]]></cardHolderName></payment>";
$xml = simplexml_load_string($xml, null, LIBXML_NOCDATA);
然后如何使用 xpath 访问 cardHolderName (John Smith)?我试过了:
$name = $xml->xpath('/payment/cardHolderName');
echo $name;
但该值为空,我收到警告:
数组到字符串的转换
所有这些 xpath 的结果相同:
'/payment/cardHolderName'
'/payment/cardHolderName[1]'
'/payment/cardHolderName/text()'
'/payment/cardHolderName[1]/text()'
提前致谢。