Javatpoint Logo
Javatpoint Logo

XML DOM


What is XML DOM

DOM is an acronym stands for Document Object Model. It defines a standard way to access and manipulate documents. The Document Object Model (DOM) is a programming API for HTML and XML documents. It defines the logical structure of documents and the way a document is accessed and manipulated.

As a W3C specification, one important objective for the Document Object Model is to provide a standard programming interface that can be used in a wide variety of environments and applications. The Document Object Model can be used with any programming language.

XML DOM defines a standard way to access and manipulate XML documents.


What does XML DOM

The XML DOM makes a tree-structure view for an XML document.

We can access all elements through the DOM tree.

We can modify or delete their content and also create new elements. The elements, their content (text and attributes) are all known as nodes.

For example, consider this table, taken from an HTML document:

The Document Object Model represents this table like this:

XML DOM

XML DOM Example : Load XML File

Let's take an example to show how an XML document ("note.xml") is parsed into an XML DOM object.

This example parses an XML document (note.xml) into an XML DOM object and extracts information from it with JavaScript.

Let's see the XML file that contains message.

note.xml

Let's see the HTML file that extracts the data of XML document using DOM.

xmldom.html

Test it Now

Output:

Important Note

To: sonoojaiswal@javatpoint.com
From: vimal@javatpoint.com
Message: Hello XML DOM

XML DOM Example : Load XML String

This example parses an XML string into an XM DOM object and then extracts some information from it with a JavaScript.

Let's see the HTML file that extracts the data of XML string using DOM.

xmldom.html

Test it Now

Output:

Important Note2

To: Sania Mirza
From: Serena William
Message: Don't forget me this weekend!

Next TopicXML Database




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


B.Tech / MCA