1
拥有如此形成的xml文件:如何获取xml文件中的节点数量?
<book id="1">
<chapter id="1">
...
</chapter>
<chapter id="2">
...
</chapter>
<chapter id="3">
...
</chapter>
</book>
我怎么能指望内部节点...? 在上面的例子中,函数应该变为3,因为结果是三个节点。
注: 我访问...所以:
$xpath = new DOMXPath($filename);
$book = $xpath->query("//book[@id='1']")->item(0);
你尝试使用'xpath'或'xquery'? – Jagrut
我使用domxpath。 –
@MarcelloImpastato:请检查我编辑的答案 –