Click to See Complete Forum and Search --> : Help with iterating through XML


damon2003
10-16-2006, 07:54 AM
Hi,

I have the following XML, this is just the first part but it continue for many rows.

This is produced by another tool.
There is a first set of nodes as follows. Then this set of nodes is repeated futher down within a set of translation nodes.

<name>
<tooltip>
<description>

My task is to take the content of the first set of nodes and copy it into the nodes with the translation nodes. Can anyone give me any suggestions about how to go about this. I have tried some Javscript with loadxml but am having problems with some of the nodes being empty. Also when the nodes are empty the XML is <footnote/>. Is this valid XML? Does DOM recognize this?

<translations language="ET" country="EE">

<items type="car">
<item id="345aa894-9e5a-41ea-b76b">
<name>GS 300</name>
<tooltip>GS 300</tooltip>
<description>
GS 300. 3.0 litre V6 VVT-i petrol, 6 speed automatic
</description>
<footnote/>
<translation>
<name/>
<tooltip/>
<description/>
<footnote/>
</translation>
</item>

<item id="e518c947-f9f9-4eb5-90be">
<name>GS 430</name>
<tooltip>GS 430</tooltip>

<description>
GS 430. 4.3 litre V8 VVT-i petrol, 6 speed automatic
</description>
<footnote/>

<translation>
<name/>
<tooltip/>
<description/>
<footnote/>
</translation>
</item>

thanks for any help,

Kor
10-16-2006, 10:48 AM
<something attribute="value" /> is an XHTML notation (note that you must have a space before the slash in case the element has attrbutes) and it is used for some of the elements, not for all. Anyway, it is not not an genuine XML notation (is an XHTML one). As far as I know, in XML you always need a tag and an end tag

<something>.......</something>

damon2003
10-16-2006, 11:09 AM
Hi,

thanks for the reply. So if it is not proper XML notation then will I have trouble trying to use DOM functions to manipulate it?


Maybe I can close all the tags first if necessary?


By the way is the way that Javascript, ASP and .net handle DOM similar?

thanks,

Kor
10-16-2006, 11:29 AM
the notation <sometag /> is used in XHML (so that in XML as well) only for the so called "empty-element tags"

http://www.w3.org/TR/2000/REC-xml-20001006#sec-starttags

Well, an XML DB structured-like file has no "empty-element tags", as in fact all the tags are invented by the programmer. The "empty-element tags" are inherited from HTML (img, br, input...). They are HTML native elements. In a DB structured XML file all the tags must be like <tag>........</tag>. The variant <tag /> has no sense, as you have no "empty-element tag" to note on it.

In an intuitive way, the empty tag notation was introduced in XHTML in order to include HTML as well in the XML structured coding. It is only a manner to alert the interpretor that it must not search for an </tag> (in case of "empties") as it should have done for straight XML notation.