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/