Source Code : Traversing a Tree of XML Nodes Using On-Demand Functions

PHP Is Open Source Programming Language You Can Download and use It, You required xampp server and wamp server . You download From xampp server from https://www.apachefriends.org/download.html. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://php.net/. Click Here or search from google with Libraries Name you get jar file related it and also http://php.net/ is a official site

Traversing a Tree of XML Nodes Using On-Demand Functions

 
<?php

$doc = new DomDocument("1.0");
$doc->loadXML( file_get_contents("data.xml") );
$root = $doc->firstChild;
$pointer = $root;

do {
  print $pointer->tagName."<br />
";
} while ( $pointer = next_element( $pointer ) );

function next_element( DomNode $pointer ) {
  while ( $pointer = next_node( $pointer ) ) {
    if ( $pointer->nodeType == XML_ELEMENT_NODE ) {
      return $pointer;
    }
  }
  return false;
}

function next_node( DomNode $pointer ) {
  if ( $pointer->hasChildNodes() ) {
    return $pointer->firstChild ;
  }
  if ( $next = $pointer->nextSibling ) {
    return $next;
  }
  while( $pointer = $pointer->parentNode ) {
    if ( $next=$pointer->nextSibling ) {
      return $next;
    }
  }
}
?>
  
  

Thank with us