Marcello Impastato Marcello Impastato - 5 months ago 28
PHP Question

how get number of nodes inside a xml tag?

Having a xml file so formed:

<book id="1">
<chapter id="1">
<chapter id="2">
<chapter id="3">

How i can count nodes inside ... ?
In example above, the function should be turn 3 as result becouse present three nodes.

I access to ... so:

$xpath = new DOMXPath($filename);
$book = $xpath->query("//book[@id='1']")->item(0);


You can do as:

Refer: $dom->getElementsByTagName('chapter')->length;