Hi,
I have the following XML content in a file (main.xml):
<?xml version="1.0" encoding="iso-8859-1"?>
<menu>
<option title="Home" href="home.php" >
<option title="News" href="news.php" >
<option title="Recent News" href="recentnew s.php" />
<option title="Archive" href="archive.p hp" />
</option>
<option title="About me" href="news.php" />
<option title="Disclaim er" href="news.php" />
</option>
<option title="Gallery" href="gallery.p hp">
<option title="Painting s" href="paintings .php" />
<option title="Drawings " href="drawings. php" />
</option>
<option title="Links" href="links.php " />
<option title="Contact" href="contact.p hp" />
</menu>
I am using the following code to hopefully output the name of the first
node by traversing the tree:
$xml_doc = domxml_open_fil e('xml/main.xml');
$node = $xml_doc->document_eleme nt(); //find the xml root
$node = $node->first_child( ); //locate the first_child node
print $node->node_name(); //output the node name
Unfortunetely, when I go run it - instead of outputing 'option', it
outputs:
#text
Im just starting with this but I also hope to output the attributes
too. How would I do this for just the first node using something
similar to the code above?
Can somebody please start me of on the right foot. What I hope to do is
to build a script that will traverse each node in order. Ill probably
have more questions as I learn more about what Im trying to do. Cheers
Burnsy
I have the following XML content in a file (main.xml):
<?xml version="1.0" encoding="iso-8859-1"?>
<menu>
<option title="Home" href="home.php" >
<option title="News" href="news.php" >
<option title="Recent News" href="recentnew s.php" />
<option title="Archive" href="archive.p hp" />
</option>
<option title="About me" href="news.php" />
<option title="Disclaim er" href="news.php" />
</option>
<option title="Gallery" href="gallery.p hp">
<option title="Painting s" href="paintings .php" />
<option title="Drawings " href="drawings. php" />
</option>
<option title="Links" href="links.php " />
<option title="Contact" href="contact.p hp" />
</menu>
I am using the following code to hopefully output the name of the first
node by traversing the tree:
$xml_doc = domxml_open_fil e('xml/main.xml');
$node = $xml_doc->document_eleme nt(); //find the xml root
$node = $node->first_child( ); //locate the first_child node
print $node->node_name(); //output the node name
Unfortunetely, when I go run it - instead of outputing 'option', it
outputs:
#text
Im just starting with this but I also hope to output the attributes
too. How would I do this for just the first node using something
similar to the code above?
Can somebody please start me of on the right foot. What I hope to do is
to build a script that will traverse each node in order. Ill probably
have more questions as I learn more about what Im trying to do. Cheers
Burnsy
Comment