Outputing an XML file

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View


I have the following XML content in a file (main.xml):

<?xml version="1.0" encoding="iso-8859-1"?>
  <option title="Home" href="home.php">
    <option title="News" href="news.php">
      <option title="Recent News" href="recentnews.php" />
      <option title="Archive" href="archive.php" />
    <option title="About me" href="news.php" />
    <option title="Disclaimer" href="news.php" />
  <option title="Gallery" href="gallery.php">
    <option title="Paintings" href="paintings.php" />
    <option title="Drawings" href="drawings.php" />
  <option title="Links" href="links.php" />
  <option title="Contact" href="contact.php" />

I am using the following code to hopefully output the name of the first
node by traversing the tree:

$xml_doc = domxml_open_file('xml/main.xml');

$node = $xml_doc->document_element(); //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


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


Re: Outputing an XML file

bissatch@yahoo.co.uk wrote:
Quoted text here. Click to load it

Because of the indentation, the first node after the root element, actaully
is a text node. What you need to do is tell the parser that it should ignore
empty text nodes.

This is done by using the DOMXML_LOAD_DONT_KEEP_BLANKS constant as the
second argument of domxml_open_file():

$xml_doc = domxml_open_file('option.xml', DOMXML_LOAD_DONT_KEEP_BLANKS);


Site Timeline