By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,409 Members | 1,604 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,409 IT Pros & Developers. It's quick & easy.

Outputing an XML file

P: n/a
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="recentnews.php" />
<option title="Archive" href="archive.php" />
</option>
<option title="About me" href="news.php" />
<option title="Disclaimer" href="news.php" />
</option>
<option title="Gallery" href="gallery.php">
<option title="Paintings" href="paintings.php" />
<option title="Drawings" href="drawings.php" />
</option>
<option title="Links" href="links.php" />
<option title="Contact" href="contact.php" />
</menu>
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
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

Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
bi******@yahoo.co.uk wrote:
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


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);
JW

Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.