XML DOM Set Node - XML DOM

How to change the value of the nodes in XML DOM object?

The value of the nodes can be changed as follows:

If in case the node to be a Attribute, then the variable ‘Value’ will be the attribute value and in case the node to be a Text, the value will be the text content and for the Element the value will be null.

The node value settings for each type of the node like attribute, text node and element is demonstrated below:

The node.xml used in all the following examples is as below:

Change Value of Text Node

Changing the value of the Node element implies editing the text content of an element or a text node. The example demonstrating the change in the text node of the element is as follows:

Example

An XML document, node.xml is parsed into an XML DOM object and the value of the text node of the element is changed. In the following example, Email of each of the Employee is changed to support@xyz.com and the values are printed.

Execution

The file is saved as set_text_node_example.htm on the server path and should be on the same path of the server as that of node.xml. The following output appears:

Change Value of Attribute Node

The change in the attribute node of the element is demonstrated below:

Example

An XML document node.xml is parsed into an XML DOM object and the value of the element’s attribute node is changed. Here, the Category of each Employee is changed to admin-0, admin-1, admin-2 and the values are printed.

Execution

The file is saved as set_node_attribute_example.htm on the server path and should be on the same path of the server as that of node.xml. The following output appears:

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

XML DOM Topics