How to Change method in XML DOM
In this articles i am going to explain about how to use XML DOM Change node.
We change value of an element in DOM
-
DOM is a collection of node, and DOM node do not have a text value.
-
The text node is store the value in a child node.
-
Node text is the way to get the value of the child node.
-
The getElementsByTagName() method returns a node list.
-
Node list containing all elements in same order as they appear source documents.
We change the value in a text node
The nodeValue property is used to change the value of a text node.
Example
The following code changes the text node value:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="loadxmldoc.html">
</script>
</head>
<body>
<script type="text/javascript">
xmlDoc = loadXMLDoc("library.xml");
a = xmlDoc.getElementsByTagName("title")[0].childNodes[0];
a.nodeValue = "C# Language";
document.write(a.nodeValue);
</script>
</body>
</html>
|
Define the code
- First we create XML http object and open it.
- XML http script send the request to the server.
- "loadxmldoc.html" get the data.
- Set the response as an XML DOM object.
- Document. write is print the document
- Change the node value of the text node to "C# language"
You may also want to read these related articles :
Ask Your Question
Got a programming related question? You may want to post your question here
Programming Answers here