A DOM (Document Object Model) defines a standard way for accessing and manipulating documents.
The XML DOM defines a standard way for accessing and manipulating XML documents.
The XML DOM views an XML document as a tree-structure.
All elements can be accessed through the DOM tree. Their content (text and attributes) can be modified or deleted, and new elements can be created. The elements, their text, and their attributes are all known as nodes.
The HTML DOM defines a standard way for accessing and manipulating HTML documents.
All HTML elements can be accessed through the HTML DOM.
You can learn more about the HTML DOM in our HTML DOM tutorial.
To extract the text "Guru" from the <to> element in the XML file above ("demofile.xml"), the syntax is:
Note: even if the XML file contains only ONE <to> element you still have to specify the array index [0]. This is because the getElementsByTagName() method returns an array.
The Below example parses an XML string into a XML DOM object and then extracts some info from it with a JavaScript:
Your Query was successfully sent!