X
<?php 
$dom 
= new domDocument(); 
$dom->load(dirname(__FILE__) . '/book.xml'); 
 
show_node_childs($dom->documentElement); 
 
// Rekursive Funktion zum Traversieren des Dokument-Baums 
function show_node_childs($node) { 
  foreach (
$node->childNodes as $child) { 
    if (
$child->nodeType == XML_ELEMENT_NODE){ 
      if (
$id $child->getAttribute("id")) { 
        echo 
"ID -> " $id "\n"
      } 
      echo 
$child->nodeName " => " $child->nodeValue "\n"
      if (
$child->hasChildNodes()) { 
        
show_node_childs($child); 
      } 
    } 
  } 

?>
X
title => This is an Example-Book
ID -> 1
chapter =>   
    Title from Chapter 1  
    Text in chapter 1  
  
title => Title from Chapter 1
para => Text in chapter 1

ID -> 2
chapter =>   
    Title from Chapter 2  
    Text in chapter 2  

title => Title from Chapter 2
para => Text in chapter 2