XML DOM Browser Differences
Browser Differences in DOM Parsing
All modern browsers support the W3C DOM specification.
However, there are some differences between browsers. One important difference is:
- The way they handle white-spaces and new lines
DOM - White Spaces and New Lines
XML often contains new line, or white space characters, between nodes. This is often the case when the document is edited by a simple editor like Notepad.
The following example (edited by Notepad) contains CR/LF (new line) between each line and two spaces in front of each child node:
<author>Giada De Laurentiis</author>
Internet Explorer will NOT treat empty white-spaces, or new lines as text nodes, while other browsers will.
The following code fragment displays how many child nodes the root element (of books.xml) has:
document.write("Number of child nodes: " + x.length);
Try it yourself »
- Load "books.xml" into xmlDoc using loadXMLDoc()
- Get the child nodes of the root element
- Output the number of child nodes
- The result is different depending on which browser you use. IE9 and earlier will alert 4 child nodes, while IE10 and other browsers will alert 9 child nodes
Thank You For Helping Us!
Your message has been sent to W3Schools.