XML DOM
DOM
(Document Object Model)
- defines a standard way for accessing and manipulating documents
- views XML documents as a tree-structure
Accessing XML through DOM
- All elements of an XML can be accessed through the DOM tree
- XML content (text and attributes) can be modified or deleted, and new elements can be created
- XML elements, their text, and their attributes are all known as nodes
Example
In
the examples below we use the following DOM reference to get the text from the
<to> element:
xmlDoc.getElementsByTagName("to")[0].childNodes[0].nodeValue.
xmlDoc - the XML document created by
the parser.
getElementsByTagName("to")[0]
- the first <to> element
childNodes[0] - the first child of the
<to> element (the text node)
nodeValue - the value of the node (the
text itself)
HTML DOM
- HTML DOM (HTML Document Object Model)
- defines a standard way for accessing and manipulating HTML documents
- All HTML elements can be accessed through the HTML DOM
Example
In
the examples below we use the following DOM reference to change the text of the
HTML element where id="to":
document.getElementById("to").innerHTML=
document - the HTML document
getElementById("to") - the
HTML element where id="to"
innerHTML - the inner text of the HTML
element