<?php
header('Content-Type: text/plain');
$xpath = "//text[@id='3']";
/* Datei einlesen */
$doc = xmldocfile('test.xml');
echo "XPath \"$xpath\":\n\n";
/* Neuen Context erstellen fuer XPath */
$con = $doc->xpath_new_context();
/* XPath auswerten ($nodes ist Klasse XPathObject) */
$nodes = $con->xpath_eval_expression($xpath);
/* Die Ergebnismenge ausgeben... */
foreach($nodes->nodeset as $node) {
echo "\t",$node->tagname,":\n";
/* Die Kind-Knoten nach dem Text-Node durchsuchen... */
foreach(domxml_children($node) as $child) {
if ($child->type == XML_TEXT_NODE) {
echo "\t\t",$child->content,"\n";
}
}
}
/* Zum Schluss noch entwas hinzufuegen... */
$root = $doc->root();
$node = $root->new_child('mytest');
$node->set_attribute('
ip',$REMOTE_ADDR);
echo "\n\n************************************\n\n";
echo $doc->dumpmem();