DOM browser
XML DOM Browser differences
Browser differences in DOM parsing
All modern browsers support W3C DOM specification.
However, there are differences between browsers. One important difference is:
How whitespace and line breaks are handled
DOM - Whitespace and line breaks
XML often contains newlines or whitespace characters between nodes. This is often the case when editing a document using a simple editor such as Notepad.
The following example (edited by Notepad) contains CR/LF (line feed) between each line and two spaces before each child node:
<title>Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
Internet Explorer will not treat empty whitespace or newlines as text nodes, while other browsers will.
The following code snippet shows how many child nodes the root element (of books.xml) has:
Example
<!DOCTYPE html> <html> <head> <script src="loadxmldoc.js"></script> </head> <body> <script> xmlDoc=loadXMLDoc("books.xml"); x=xmlDoc.documentElement.childNodes; document.write("Number of child nodes: " + x.length); </script> </body> </html>
Run Example»
Click the "Run Example" button to view the online example
Explanation of the example:
Use loadXMLDoc() to load "books. xml" Load xmlDoc
Get the child nodes of the root element
Output the number of child nodes. The results depend on the browser you are using. Internet Explorer will output 4 (alert 4 child nodes), while other browsers will output 9 (alert 9 child nodes).