Jump to content

XML parsing - not repeating


Steven
 Share

Recommended Posts

Hi all,First I want to say that I have been using W3schools for quite a while now and am forever in debt to you guys who have made this site possible!Now to the annoying part:I have just started to dabble with XML. I made a simple xml file and embedded it into an html file according to the data islands tutorial found on the site (here). The page functioned great and displayed the entire xml file with me only showing the first "set" from the xml. Here's what I mean, just to be clear:XML

	<panzer>		<name>PzKpfw I</name>		<weight>5300kg</weight>		<crew>2 men</crew>		<engine>krupp M305, 4-cylinder, 57hp</engine>		<speed>37km/h</speed>		<range>145km road, 100km country</range>		<fuel>144 litres</fuel>		<armament>2x MG13 Dreyse 7.92mm</armament>	</panzer>

HTML Data Island

<table width="100%" border="1" cellpadding="10" cellspacing="0" bordercolor="#000000" datasrc="#library">  <tr>	<td colspan="2" bgcolor="#CCCCCC"><span id="name"></span></td>  </tr>  <tr>	<td>Weight:</td>	<td><span id="weight"></span></td>  </tr>  <tr>	<td>Crew:</td>	<td><span id="crew"></span></td>  </tr>  <tr>	<td>Engine:</td>	<td><span id="engine"></span></td>  </tr>  <tr>	<td>Speed:</td>	<td><span id="speed"></span></td>  </tr>  <tr>	<td>Range:</td>	<td><span id="range"></span></td>  </tr>  <tr>	<td>Fuel capacity:</td>	<td><span id="fuel"></span></td>  </tr>  <tr>	<td>Armament:</td>	<td><span id="armament"></span></td>  </tr></table>

The XML file includes 7 <panzer> sets of code (each different pzkpfw models from WW2), and the data island displayed all 7 of those sets even though I had 1 table displaying only one of each tag. This was all well and good, until I discovered that this worked in IE only, and not FF. Then I found my way to the parsing tutorial on the website (here).I inserted the code from the first example on that page, and it worked at last in Firefox... but it does not display all 7 of the "panzers," but only the first one. How can I get it to repeat like the simple data island?I uploaded the files so you can see all of the code:* http://www.theudo.net/xml-panzer/index.html* http://www.theudo.net/xml-panzer/panzer.xml--One thing I did notice, is that the <library> element from the xml file is not expressed in the code in the html file. I think that may be the problem, but how and where do I insert the <library> element in all of that code? I haven't gotten around to javascript yet :)Thanks a bunch in advance!- Steven

Link to comment
Share on other sites

Well, you should learn JavaScript if you want to use XML inside HTML pages like that.But know that "parser" doesn't always imply JavaScript, contrary to the tutorial. A "parser" is a program that reads XML and allows you to get specific data out of it by traversing its DOM tree representation. This program however can be run on the server too.Having that said, if you can't quite understand JavaScript just yet, you can safely go to something simpler like PHP, and more precisely, the PHP5 DOM. If you understand that, JS will start making much more sence to you.Also, if you use PHP5 DOM, instead of JavaScript DOM, all users will be able to see the result, because the server generates HTML code based on the XML. With JavaScript, the client must have JavaScript available, and XML support to it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...