php - How to get number of nodes inside a xml file? -


having xml file formed:

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

how can count nodes inside ... ? in example above, function should turn 3 result becouse present 3 nodes.

note: access ... so:

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

you can as:

refer: http://de2.php.net/manual/en/book.dom.php

$dom->getelementsbytagname('chapter')->length; 

unless can use this:

$xpath->evaluate('count(//book/chapter'); 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -