473,408 Members | 1,867 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,408 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 22477
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.