XML DOM Browser Differences
Browser Differences in DOM Parsing
All modern browsers support the W3C DOM specification.
However, there are differences between browsers. A significant difference is:
- The way they handle whitespace and line breaks
DOM - Whitespace and Line Breaks
XML often contains line breaks or whitespace characters between nodes. This is common when editing documents with simple editors like Notepad.
The following example (edited with Notepad) includes CR/LF (line breaks) between each line and two spaces before each child node:
Internet Explorer will not treat empty whitespace or line breaks as text nodes, while other browsers will.
The following code snippet shows how many child nodes the root element has (from books.xml):
Example
Example explanation:
Use loadXMLDoc() to load "books.xml" into xmlDoc
Get the child nodes of the root element
Output the number of child nodes. The result depends on the browser you use. IE will output 4 (indicating 4 child nodes), while other browsers will output 9 (indicating 9 child nodes).