Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old February 11th, 2006, 12:17 AM
Newbie
 
Join Date: Feb 2006
Posts: 1
Unhappy Parsing empty XML nodes in JavaScript

Hi there;

I have the following problem. I am using one of the many javascript XML parsing scripts available around the Internet, but the parsing fails when it reach an XML child node that is empty, as in the example below:

<FirstName>John</FirstName>
<MiddleInitial></MiddleInitial>
<LastName>Smith</LastName>

John Smith does not have a middle initial. When the parsing scripts I tried reach this node, it fails with a message such as "Object Required" or some other error message.

I tried the following commands to no avail:

x[i].childNodes[j].firstChild.length == 0
x[i].childNodes[j].firstChild.nodeValue == ""

but it always fail.

What I need is for a way to recognize that that particular field is empty and allow me to put a space or a &nbsp; in its place without crashing.

Any ideas are welcome.

Thanks for your time. :confused:
Reply
  #2  
Old June 14th, 2006, 06:28 PM
fen fen is offline
Newbie
 
Join Date: Jun 2006
Posts: 1
Default

Anyone know the answer? I am also having the same issue :(
Such a PITA!
Any help would be highly appretiated.
Reply
  #3  
Old August 12th, 2006, 07:41 PM
Newbie
 
Join Date: Aug 2006
Posts: 1
Default

// Try this guys:

if (xml.getElementsByTagName('job_number')[i].hasChildNodes())
{
rowData += xml.getElementsByTagName('job_number')[i].firstChild.data;
}
else
{
rowData += '';
}
Reply
  #4  
Old November 16th, 2006, 10:10 PM
Newbie
 
Join Date: Nov 2006
Posts: 1
Default

This works to me....

temp=nodes[i].firstChild;

if (document.getElementById(id)!=null && temp!=null)

Hope u can use it....

Abe.
Reply
Reply

Bookmarks

Thread Tools

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 Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles