我试图使用PHP和XPath从这个XML中获取 ID元素为1364的所有Category节点:http://education.oracle.co.uk/html/oracle/28US/schedule.xml
我的代码目前看起来像这样:
$schedule = new SimpleXMLElement("schedule.xml", null, true);
$nodes = $schedule->xpath("//category[id=1364]");
if(!$nodes) {
echo "No xpath results.";
} else {
echo count($nodes)." results.";
}
Run Code Online (Sandbox Code Playgroud)
XPath不返回任何结果.我已使用其他XPath查询程序检查了查询,并返回了结果.
上面的代码使用SimpleXML,但是在使用DOMDocument时我遇到了完全相同的问题.在SimpleXML和DOMDocument中,运行XPath"//*"都有效,返回文档中的所有节点.
谢谢!