Outputing an XML file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bissatch@yahoo.co.uk

    Outputing an XML file

    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

  • Janwillem Borleffs

    #2
    Re: Outputing an XML file

    bissatch@yahoo. co.uk wrote:[color=blue]
    > 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
    >[/color]

    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_DON T_KEEP_BLANKS constant as the
    second argument of domxml_open_fil e():

    $xml_doc = domxml_open_fil e('option.xml', DOMXML_LOAD_DON T_KEEP_BLANKS);


    JW



    Comment

    Working...