The best Advanced XML DOM Tutorial In 2024, In this tutorial you can learn XML DOM - Advanced,Gets the value of the element,Examples,Gets the value of the property,Examples,Change the value of the element,Examples,Create a new property,Examples,Create element,Examples,Removing elements,Examples,
In the earlier chapters of this tutorial , we introduced the XML DOM, and uses the XML DOM getElementsByTagName () method to retrieve data from XML documents.
In this chapter we will combine a number of other important XML DOM methods.
You can in our XML DOM tutorial to learn more about the XML DOM knowledge.
XML files used in the following examples: the Books.xml .
The following example retrieves the first text value of the <title> element:
The following example retrieves the text value of the first <title> element of the "lang" attribute:
The following example changes the first text value <title> element:
The XML DOM setAttribute () method can be used to change the existing property value, or create a new property.
The following example creates a new attribute (edition = "first"), and then add it to each <book> element:
The XML DOM createElement () method creates a new element node.
The XML DOM createTextNode () method creates a new text node.
The XML DOM appendChild () method adds a child node to node (after the last child node).
To create a new element with text content, you need to create a new element node element and a new text node, and then he added to the existing nodes.
The following example creates a new element (<edition>), with the following text: First, and then add it to the first <book> element:
Examples explained
The following example remove the first <book> element of the first node:
NOTE: The above examples may result depending on the browser and different.Firefox treats new lines as empty text nodes, Internet Explorer is not the case. You can in our XML DOM tutorial in reading more about this problem and how to avoid it.