May 27, 2021 XML DOM
DOM node information refers to the fact that in XML and DOM, each node is an object.
The nodeName, nodeValue, and nodeType properties contain information about the node.
The following example uses the XML
file .xml.
The
function loadXMLDoc(),
located in an external JavaScript, is used to load XML files.
Gets the node name of the element node
This example uses the nodeName property to get the .xml name of the root element in "books."
Get text from the text node
This example uses the nodeValue property to get the text .xml the first element in the "books.xml " .
Change the text in the text node
This example uses the nodeValue property to change the text .xml the first element in the "books".
Gets the node name and type of the element node
This example uses the nodeName and nodeType properties to get the node name .xml the root element in "books and books".
In XML DOM, each node is a single object.
Objects have methods and properties that can be accessed and operated through JavaScript.
The three important node properties are:
The nodeName property specifies the name of the node.
The nodeValue property specifies the value of the node.
The following code retrieves the value of the text node of the first element:
RESULTS: txt - "Everyday Italian"
Example explanation:
The following code changes the value of the text node of the first element:
Example explanation:
The nodeType property specifies the type of node.
nodeType is read-only.
The most important node types are:
Node type | NodeType |
---|---|
element | 1 |
Attributes | 2 |
text | 3 |
Comment | 8 |
Documentation | 9 |
In the next section, we'll show you the nodes of XML DOM;