可能重复:
A simple program to CRUD node and node values of xml file
XPath and PHP: nothing works properly访问元素
$XML = <<<XML
<items>
<item id="123">
<name>Item 1</name>
</item>
<item id="456">
<name>Item 2</name>
</item>
<item id="789">
<name>Item 3</name>
</item>
</items>
XML;
$objSimpleXML = new SimpleXMLElement($XML);
echo $objSimpleXML->item[2]->name; // output: Item 3 (OK)
echo '<br><pre>';
print_r($objSimpleXML->xpath('./item[1]/name')); // output: empty Array!!!
您好!如何使用纯xpath查询获得“Item 3”作为输出? (我的建议输出一个空阵列。)
这看起来很可疑,类似于http://stackoverflow.com/questions/14280450/xpath-and-php-nothing-works-properly/14280528#14280528。 –