DOM stands for Document Object Model. To best understand what the DOM is, we will briefly discuss the HTML DOM first. When a web page is loaded, the browser creates a Document Object Model of the page. The DOM is a W3C (World Wide Web Consortium) standard. The DOM defines a standard for accessing documents: “The W3C Document Object Model (DOM) is a platform and language-neutral interface that allows programs and scripts to dynamically access and update the content, structure, and style of a document.”

In other words, the HTML DOM is a standard for how to get, change, add, or delete HTML elements. It provides full CRUD ability. (Create, Read, Update and Delete). With the object model, JavaScript gets all the power it needs to create dynamic HTML.

All XML elements can be accessed through the XML DOM. Consider the following XML document.

<?xml version="1.0" encoding="UTF-8"?>
  <book category="cooking">
    <title lang="en">Everyday Italian</title>
    <author>Giada De Laurentiis</author>
  <book category="children">
    <title lang="en">Harry Potter</title>
    <author>J K. Rowling</author>

<!DOCTYPE html>
<p id="demo"></p>
<p id="demo2"></p>
<p id="demo3"></p>
<p id="demo4"></p>
var parser, xmlDoc;
var text = "<bookstore>" + 
"<book>" +
"<title>Everyday Italian</title>" +
"<author>Giada De Laurentiis</author>" +
"<year>2005</year>" +
"</book>" +
"<book>" +
"<title>Special Occasion Italian</title>" +
"<author>Joe Blow</author>" +
"<year>2006</year>" +
"</book>" +

parser = new DOMParser();
xmlDoc = parser.parseFromString(text,"text/xml");

document.getElementById("demo").innerHTML =
document.getElementById("demo2").innerHTML =
document.getElementById("demo3").innerHTML =
document.getElementById("demo4").innerHTML =

Here is the output, courtesy of w3schools.com. I modified their code, by the way.

Series Navigation<< XML TreeXML and XPath >>

Leave a comment

Your email address will not be published. Required fields are marked *