Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Avoiding Errors with 'child nodes has no properties'
Old 02-26-2008, 06:36 PM Avoiding Errors with 'child nodes has no properties'
Extreme Talker

Posts: 168
Name: James
Location: Australia
Trades: 0
Dear Webmasters,
I have a problem with the process of an XML file, where the tag has no content.


Example of the XML code

<c></c>

The tag exists, but has no data between it.

Firefox error console returns ' Child node has no properties'



The Javascript line is, .

if (xml.getElementsByTagName("c")[a].childNodes[0].length>0) {xc=xml.getElementsByTagName("c")[a].childNodes[0].nodeValue;} else {xc=''}

I am trying to get my script to test if it is empty, but I do not know how to do it.

Must I always ensure that the tag has at least one space within it?
TRANZIT JIM is offline
Reply With Quote
View Public Profile Visit TRANZIT JIM's homepage!
 
 
Register now for full access!
Old 02-26-2008, 06:39 PM Re: Avoiding Errors with 'child nodes has no properties'
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
it's because a child node has no lenght.
You must check upon the nodeValue length:
http://developer.mozilla.org/en/docs...ment.nodeValue
Code:
if (xml.getElementsByTagName("c")[a].childNodes[0].nodeValue.length>0) {
  xc=xml.getElementsByTagName("c")[a].childNodes[0].nodeValue;
} 
else {xc=''}
I did not tested it, but I think there's where your problem lies.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to Avoiding Errors with 'child nodes has no properties'
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.29023 seconds with 12 queries