473,383 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,383 software developers and data experts.

Mozilla Vs IE for childNodes.length


HI

The Value for childNodes.length differs with mozilla and IE

Is it problem with my coding..... I could not under
stood.............
The following is the details

XML file

<track_order>
<status>0</status>
</track_order>

xmlDoc is the above XML

var n = xmlDoc.getElementsByTagName('track_order')[0];
alert(n.childNodes.length);

For Mozilla I get n.childNodes.length = 3

For IE I get n.childNodes.length = 1
Can any one please help

regards
moses

Oct 20 '06 #1
5 22476
Moses wrote:
The Value for childNodes.length differs with mozilla and IE
<track_order>
<status>0</status>
</track_order>

xmlDoc is the above XML

var n = xmlDoc.getElementsByTagName('track_order')[0];
alert(n.childNodes.length);

For Mozilla I get n.childNodes.length = 3

For IE I get n.childNodes.length = 1
Mozilla for XML and HTML document includes whitespace between elements
as text nodes in the DOM, IE does not do that for HTML at all and for
XML does not do it by default (although you can set preserveWhiteSpace =
true on an MSXML DOMDocument).
So for Mozilla that track_order element has as its first child node a
text node with white space, then the status element as the second child
and then again a text node with white space as the third child.
MSXML (used by IE) only has the element node.

That should not pose a problem at all, if you are looking for child
elements then ignore the childNodes collection and simply use
getElementsByTagName (e.g.
xmlDoc.getElementsByTagName('track_order')[0].getElementsByTagName('status')[0]
gives you the element) and/or XPath to access the child elements. If you
still think you need to loop through childNodes then include checks for
nodeType being 1 for element nodes and 3 for text nodes.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 20 '06 #2

Martin Honnen wrote:
Moses wrote:
The Value for childNodes.length differs with mozilla and IE
<track_order>
<status>0</status>
</track_order>

xmlDoc is the above XML

var n = xmlDoc.getElementsByTagName('track_order')[0];
alert(n.childNodes.length);

For Mozilla I get n.childNodes.length = 3

For IE I get n.childNodes.length = 1

Mozilla for XML and HTML document includes whitespace between elements
as text nodes in the DOM, IE does not do that for HTML at all and for
XML does not do it by default (although you can set preserveWhiteSpace =
true on an MSXML DOMDocument).
So for Mozilla that track_order element has as its first child node a
text node with white space, then the status element as the second child
and then again a text node with white space as the third child.
MSXML (used by IE) only has the element node.

That should not pose a problem at all, if you are looking for child
elements then ignore the childNodes collection and simply use
getElementsByTagName (e.g.
xmlDoc.getElementsByTagName('track_order')[0].getElementsByTagName('status')[0]
gives you the element) and/or XPath to access the child elements. If you
still think you need to loop through childNodes then include checks for
nodeType being 1 for element nodes and 3 for text nodes.

--

Martin Honnen
http://JavaScript.FAQTs.com/


Hi

Thank you....

moses

Oct 20 '06 #3
Hi
I solved the problem by

xmlDoc.getElementsByTagName('track_order')[0].getElementsByTagName('status')[0]

Since I am new to XML and want to learn more

Can u please give some more details on your last point because I
didnt understood it.
If you still think you need to loop through childNodes then include
checks for
nodeType being 1 for element nodes and 3 for text nodes.

regards
moses
Moses wrote:
Martin Honnen wrote:
Moses wrote:
The Value for childNodes.length differs with mozilla and IE
<track_order>
<status>0</status>
</track_order>
>
xmlDoc is the above XML
>
var n = xmlDoc.getElementsByTagName('track_order')[0];
alert(n.childNodes.length);
>
For Mozilla I get n.childNodes.length = 3
>
For IE I get n.childNodes.length = 1
Mozilla for XML and HTML document includes whitespace between elements
as text nodes in the DOM, IE does not do that for HTML at all and for
XML does not do it by default (although you can set preserveWhiteSpace =
true on an MSXML DOMDocument).
So for Mozilla that track_order element has as its first child node a
text node with white space, then the status element as the second child
and then again a text node with white space as the third child.
MSXML (used by IE) only has the element node.

That should not pose a problem at all, if you are looking for child
elements then ignore the childNodes collection and simply use
getElementsByTagName (e.g.
xmlDoc.getElementsByTagName('track_order')[0].getElementsByTagName('status')[0]
gives you the element) and/or XPath to access the child elements. If you
still think you need to loop through childNodes then include checks for
nodeType being 1 for element nodes and 3 for text nodes.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Hi

Thank you....

moses
Oct 20 '06 #4
Moses wrote:
I solved the problem by

xmlDoc.getElementsByTagName('track_order')[0].getElementsByTagName('status')[0]
Can u please give some more details on your last point because I
didnt understood it.
If you still think you need to loop through childNodes then include
checks for
nodeType being 1 for element nodes and 3 for text nodes.
Assuming you did e.g.
var orderElement = xmlDoc.getElementsByTagName('track_order')[0];
you could loop through the childNodes collection looking for element
nodes e.g.
if (orderElement != null) {
for (var i = 0, l = orderElement.childNodes.length; i < l; i++) {
var child = orderElement.childNodes[i];
if (child.nodeType === 1) {
// you have an element node here
}
}
}

--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 20 '06 #5

Hi

Thank u very much for ur help I got it.......

regards
moses

Martin Honnen wrote:
Moses wrote:
I solved the problem by

xmlDoc.getElementsByTagName('track_order')[0].getElementsByTagName('status')[0]

Can u please give some more details on your last point because I
didnt understood it.
If you still think you need to loop through childNodes then include
checks for
nodeType being 1 for element nodes and 3 for text nodes.

Assuming you did e.g.
var orderElement = xmlDoc.getElementsByTagName('track_order')[0];
you could loop through the childNodes collection looking for element
nodes e.g.
if (orderElement != null) {
for (var i = 0, l = orderElement.childNodes.length; i < l; i++) {
var child = orderElement.childNodes[i];
if (child.nodeType === 1) {
// you have an element node here
}
}
}

--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 20 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: tony kulik | last post by:
This code works fine in ie and opera but not at all in Mozilla. Anybody got a clue as to how to get it right? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <script...
2
by: KB | last post by:
Hi folks, I'm trying to adopt microsoft-specific code to mozilla. I have an xml file which I can't figure out how to parse using the XMLDocument object: <?xml version="1.0" encoding="utf-16"...
6
by: hsomob1999 | last post by:
so i have a <ul> and I allow the user to append items to it. The problem is that on mozilla the <span class="line"> which is just a line to divide the sections gets overlaped and doesnt move down...
6
by: Luke Dalessandro | last post by:
I'm not sure if this is the correct forum for platform specific (Mozilla/Firefox) javascript problems, so just shout and point me to the correct newsgroup if I'm being bad. Here's the deal... ...
2
by: partridge | last post by:
I'm sure it's not mozilla's fault but I'm at a loss here. I'm loading the following XML data into a page using http_request: <?xml version="1.0" encoding="iso-8859-1"?> <forum> <message...
7
by: Aziz | last post by:
Hi Folks I am trying to access an HTML code stored as CDATA section in the xml file listed bellow: <?xml version="1.0"?> <results count="5"> <!]> </results> The xml tree is the responseXML...
2
by: ErkA | last post by:
Hello sorry of omy pure english ;) I think, that something wrong is in mozilla *FF 1,5,0,2* I'm trying to parse a xml file http://bazarek.pl/txt/note.xml by XMLHttpRequest method. In IE,...
1
by: newToAjax | last post by:
I have created an ajax application which retrievs an xml file and fills in the tab fields on the form.The code works fine in IE while its does not in Mozilla. Can you please let me know if i have to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.