473,320 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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="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
1 1711
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Antonio Ooi | last post by:
Hi, Probably due to my 'Language for non-Unicode Setting' in Regional Settings, my ASP page keeps outputing the date format as Chinese Simplified characters when issuing say, <%=Now()%>. In...
4
by: George | last post by:
I am lost on how to do this. I have not worked with C much at all but can understand the basic properties of this language. Could someone please show me or explain to me how to write a function...
1
by: John Cantley | last post by:
I need to output the a copyright symbol to a text file. However, when a third party app imports this textfile I get an eifel tower looking symbol preceding it. Textpad doesn't show it but Wordpad...
4
by: jdcrief | last post by:
Using Visual C++2005 Expression Edition Having trouble outputting the value referenced by the pointer and then outputing the address of the pointer for the char. Any ideas would be greatly...
2
by: eric dexter | last post by:
I need to take text from one file and then save it to a different file. I also need to return any comment The def should have variables for the file that should be read in, the file it should...
1
by: JanaB | last post by:
I am writing a code that needs to read in a binary file. At the moment I don't have to do anything with the data, I just need to view the contents to compare its structure with another binary file....
3
by: tariq103 | last post by:
I am having trouble with a normally simple function, I am trying to read a text file and output what is in the file: #include <iostream> #include <cmath> #include <iomanip> #include <fstream>...
8
by: Jon Slaughter | last post by:
can one "stream" image data to a browser? I created an image using gd and when I do imagepng I just get the binary data for the image written as text instead of the image itself. Now I'm...
9
by: flin2k | last post by:
I'm using XSLT to process an inbound xml file and wanted to translate all the ® to &reg; but it's not allowing me to put in a & symbol. When I use &amp;reg; it's outputing &amp;reg. How can I get the...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.