XML php get xpath next node from loop or how to loop from xpath parents



I have xml



<tag>
<id>106</id>
<title>DG</title>
</tag>
<tag>
<id>1</id>
<title>DjG</title>
</tag>


I use this code



$dom = new DomDocument();
$dom->loadXml($xml);
$xpath = new DOMXPath($dom);
echo count($xpath->evaluate('//tag/*'));
foreach ($xpath->evaluate('//tag/*') as $i=>$node) {
echo $xpath->evaluate('local-name(parent::*)', $node) . "=" .$i . "\n";
}


I cant get each tag node and get all childrens something like this



1 tag=1 tag=2 tag=3 tag=4



but how to get



2


tag=1 tag=2



and how to count tags and print_r($node) each node?


No comments:

Post a Comment