Marcello Impastato Marcello Impastato - 1 year ago 58
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);

Answer Source

You can do as:

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


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download