...

Error: empty-xml-tag-nodesValue

Jerome
03-20-2003, 04:32 PM
Hi,

I have an xml-file like:

<index>

<data>
Hello
</data>

<data>
World
</data>

<data>
</data>

</index>

Thus the last data-tag without a value (empty), then I get an error message. When I make a file with a deeper structure and I leave the tag without value out of the file it's not working either, which in this case I can understand, but a Tag without value not working?

Is it necessary to write a work-around, NAN? or how do I handle this?

Thanks for Your effort,
Jerome

Alex Vincent
03-21-2003, 01:24 AM
Um, what platform and script are you running that XML file through? The file is well-formed, so there's not much we can do to help you unless we know what you're trying to do, exactly.

Jerome
03-21-2003, 10:23 AM
Thanks for replying, sorry for not being very clear, here are the details:

1. HTML-file with JavaScript function
2. External XML-file with data

The JavaScript function:
{
nodelist=xmlDoc.getElementsByTagName("it");
dataStr+='<TABLE>';
for(i=0;i<=nodelist.length-1;i++)
{
a=nodelist[i].childNodes[0].childNodes[0].nodeValue;
b=nodelist[i].childNodes[1].childNodes[0].nodeValue;
c=nodelist[i].childNodes[2].childNodes[0].nodeValue;
dataStr+='<TR><TD>'+a+'</TD><TD>'+b+'</TD><TD>'+c+'</TD></TR>';
}
dataStr+='</TABLE>';
MyDIV.innerHTML=dataStr;
}

The XML-file:

<?xml version="1.0"?>
<kl2>
<it>
<tp>208</tp>
<lt>1990 - 1992</lt>
<lk>link1</lk>
</it>
<it>
<tp>308</tp>
<lt>1992 - 1994</lt>
<lk>link2</lk>
</it>
<it>
<tp>408</tp>
<lt>1994 - 1996</lt>
<lk>link3</lk>
</it>
<it>
<tp>508</tp>
<lt></lt>
<lk>link4</lk>
</it>
</kl2>
The question:

I get an error when one of the childs has no value, in other words it's empty (see the last - lt - Tags).

The XML-files I have are like this, sometimes no value available

Is there a work-around to examen empty fields?

Thanks for Your effort,
Jerome

Alex Vincent
03-22-2003, 01:07 AM
Hm. Well, NodeList interfaces have an item() method and a length property. childNodes properties are considered NodeList objects.

Also, when you ask for a property from DOM which isn't there, you get a null value back.

Here's what I'd do:


a=nodelist[i].childNodes[0].firstChild;
b=nodelist[i].childNodes[1].firstChild;
c=nodelist[i].childNodes[2].firstChild;
if (a && b && c) {
dataStr+='<TR><TD>'+a.nodeValue+'</TD><TD>'+b.nodeValue+'</TD><TD>'+c.nodeValue+'</TD></TR>';
}

Jerome
03-22-2003, 09:28 AM
Hm., this means the complete -record - will not show up when one off 3 values not exist. However what I like is:

a or b or c available.
Show record (table.row) with filled or empty cells depending on the availabillity of a value, f.e.

The table looks like:
208 1990 - 1992 link1
308 1992 - 1994 link2
408 1994 - 1996 link3
508 (empty cell) link4

I think I have to examen a - null - or - NaN - value.

Jerome

Jerome
03-23-2003, 11:05 AM
Alex,

It has nothing to do with removing white-spaces, does it? Otherwise I am completely......I am using IE 5.0, where this should not happen.

Your thread:

http://www.codingforums.com/showthread.php?s=&threadid=7028

I am running out of ideas to solve this!

Jerome

Alex Vincent
03-23-2003, 11:34 PM
No, I don't think it has anything to do with whitespace text nodes.

I think you're very close; the key is how do you want to do the logic of the a, b, c flag variables?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum