473,396 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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:
Feb 11 '06 #1
3 12053
fen
1
Anyone know the answer? I am also having the same issue :(
Such a PITA!
Any help would be highly appretiated.
Jun 14 '06 #2
// Try this guys:

if (xml.getElementsByTagName('job_number')[i].hasChildNodes())
{
rowData += xml.getElementsByTagName('job_number')[i].firstChild.data;
}
else
{
rowData += '';
}
Aug 12 '06 #3
AbeMty
1
This works to me....

temp=nodes[i].firstChild;

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

Hope u can use it....

Abe.
Nov 16 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: dd | last post by:
Given the bolow sample, I need to count the elements <quick> with a child 'yes'. The result for this sample should, of couse, be '1', but I cannot figure out how to write the expression in the...
4
by: Joe Cox | last post by:
I appologize for the novice question. I believe in am using standard ECMA. Can someone explain to me why the following script works in IE but does not work in Firefox, Mozila, or Opera? ...
2
by: | last post by:
Okay, this is probably a really stupid question - but I just can't figure it out. I have a large xml document which is being transformed into another using ..net xsl - some elements inside of...
1
by: tMan | last post by:
whats the xpath to get all the empty nodes in a document. in the xml below i want to get the nodes <empty> and <t> all other nodes either have a child node or text in them <root> <test> <se>...
4
by: Michael Frost | last post by:
Loading and saving a xml document in .net creates whitespace in empty nodes! loading an empty node like: <node></node> ..net saves as: <node> </node>
6
by: Grant | last post by:
I have this simple xml file which wont ever get beyong 3 nodes deep. I need to get the value of the child node of any node with an id of '63'. So fir instance I would be returned 'False' from the...
3
by: tschwartz | last post by:
I'm trying to write a stylesheet which removes nodes which are empty as a result of other template processing. For example, given the following xml, I'd like to: - remove all "b" elements -...
5
by: jhurrell | last post by:
I have an XML file that contains some empty nodes like: <sample> <test/> <test1/> </sample> I am using Saxon 8.8 to transform this XML into another XML file, but I'd like to remove...
6
by: jackwootton | last post by:
Hello everyone, I understand that XML can be parsed using JavaScript using the XML Document object. However, it is possible to parse XHTML using JavaScript? I currently listen for DOMMutation...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.