Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

XML DOM browser differences


May 27, 2021 XML DOM


Table of contents


XML DOM browser differences

When using DOM, it is important to note that although it is supported by mainstream browsers, there are some differences.

Browser differences in DOM resolution

All modern browsers support the W3C DOM specification.

However, there are differences between browsers. An important difference is:

  • The way white space and line-ups are handled

DOM - Blank and line-over

XML often contains line-over or blank characters between nodes. This is often the case when editing a document using a simple editor, such as Note book.

The following example (edited by Note book) contains CR/LF (line-over) between each line, with two spaces before each child node:

<book>
<title>Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book> 

Internet Explorer will not use empty blanks or line-overs as text nodes, while other browsers will.

The following snippet shows how many .xml the root element (books) has:

xmlDoc=loadXMLDoc("books.xml");

x=xmlDoc.documentElement.childNodes;
document.write("Number of child nodes: " + x.length);

Try it out . . .

Example explanation:

  1. Use loadXMLDoc() to load .xml books" into xmlDoc
  2. Gets the child node of the root element
  3. The number of output child nodes. T he results depend on the browser you are using. The IE browser outputs 4 (reminder 4 child nodes), while other browsers output 9 (reminder 9 child nodes).