DOM (Document Object Model, Document Object Model) defines a set of standard methods for accessing and manipulating documents.
##XML DOM (XML Document Object Model) Definition A set of standard methods for accessing and manipulating XML documents.
DOM View XML documents as a tree structure. All elements can be accessed through the DOM tree. Their contents can be modified or deleted, and new elements created. Elements, their text, and their attributes are all considered nodes.
In the following example, we use a DOM reference to get the text from the xmlDoc.getElementsByTagName("to")[0].childNodes[0].nodeValue
xmlDoc - XML document created by the parser
getElementsByTagName("to")[0] - First
childNodes[0] - The first child element of the
nodeValue - the value of the node (the text itself)
All HTML elements can be accessed through the HTML DOM.
In the following example, we use a DOM reference to change the text of the HTML element with id="to":
document.getElementById("to").innerHTML=
document - HTML document
- where id=" to" HTML element
- The inner text of the HTML element
Parse XML file - cross-browser example
The following code Load an XML document ("note.xml") into the XML parser:
W3School.com.cn Internal Note
To:
From:
Message:
To:
GeorgeFrom: JohnMessage: Don't forget the meeting!
Important Note
To extract the text "John" from XML, the syntax is:
getElementsByTagName("from")[0].childNodes[0].nodeValue
Parsing XML String - Cross-Browser Example
The code below loads and Parse an XML string:
W3School.com.cn Internal Note
To:
From:
Message:
To: GeorgeFrom: JohnMessage: Don't forget the meeting!
Note: Internet Explorer uses the loadXML() method to To parse XML strings, other browsers use DOMParser objects.
The above are the crazy XML study notes (5)-------- ---XML DOM content, please pay attention to the PHP Chinese website (www.php.cn) for more related content!