type) { case XML_ELEMENT_NODE: for($i=0; $i<$level; $i++) echo " "; echo "<".$node->name; $attributes = $node->attributes(); if(is_array($attributes)) { //var_dump($attributes); foreach($attributes as $attribute) echo " ".$attribute->name."=".$node->getattr($attribute->name); } echo ">\n"; $children = $node->children(); for($i=0; $i < count($children); $i++) output_node($children[$i], $level+1); for($i=0; $i<$level; $i++) echo " "; echo "name.">\n"; break; case XML_TEXT_NODE: for($i=0; $i<$level; $i++) echo " "; echo $node->content; break; case XML_ENTITY_REF_NODE: echo $node->content; break; case XML_COMMENT_NODE: for($i=0; $i<$level; $i++) echo " "; echo ""; echo "\n"; break; } } function list_attr($node) { $attr = domxml_attributes($node); for(reset($attr); $key = key($attr); next($attr)) { echo $key."=".$attr[$key]."\n"; } } $xmlstr = " ]> Title &sp; a1b1c1 a2c2 a3b3c3 "; /* The following code traverses the xml tree node by node by using the methods of the xmlnode object */ echo "Test 1: accessing single nodes from php\n"; if(!$dom = xmldoc($xmlstr)) { echo "Error while parsing the document\n"; exit; } echo "XML Version: ".$dom->version."\n"; echo "Standalone: ".$dom->standalone."\n"; $dtd = $dom->dtd(); $rootnode = $dom->children(); foreach($rootnode as $root) output_node($root); $rootnode = $dom->root(); output_node($rootnode); /* This one creates a dom tree made of php objects */ echo "Test 2: creating a tree with php objects\n"; $dom = xmltree($xmlstr); $dom->root->name = "section"; var_dump($dom); echo $dom->root->name; echo "\n"; /* xmltree() creates a tree which is readonly. This means that a function like $dom->root->new_child("TEST", "ljdf"); won't work */ /* The following builds a xml document from scratch */ echo "Test 3: building a xml document from scratch\n"; $doc = new_xmldoc("1.0"); $root = $doc->add_root("HTML"); $head = $root->new_child("HEAD", ""); $head->new_child("TITLE", "Hier der Titel"); $body = $root->new_child("BODY", ""); $table = $body->new_child("TABLE", ""); $table->setattr("WIDTH", "100%"); $table->new_child("TR", " "); echo $doc->dumpmem(); $doc = new TestNode($xmlstr); var_dump($doc); ?>