【发布时间】:2011-02-15 12:40:53
【问题描述】:
我正在尝试使用 PHP 和 XPath 从该 XML 中获取 ID 元素为 1364 的所有类别节点: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.";
}
XPath 不返回任何结果。我已经使用其他XPath查询程序检查了查询,并返回了结果。
上面的代码使用了 SimpleXML,但是我在使用 DOMDocument 时遇到了完全相同的问题。在 SimpleXML 和 DOMDocument 中,运行“//*”的 XPath 都可以,返回文档中的所有节点。
谢谢!
【问题讨论】:
标签: php xml xpath simplexml domdocument