Use of remove method in XML DOM
In this articles I am going to explain about remove an element and text node in XML DOM.
We remove an Text Node
The removeChild() method is also be used to remove a text node:
<!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];
document.write("Child nodes: ");
document.write(a.childNodes.length);
document.write("<br />");
b = a.childNodes[0];
a.removeChild(b);
document.write("Child nodes: ");
document.write(a.childNodes.length);
</script>
</body>
</html>
|
Define the code
- "loadxmldoc.html" get the data.
- Set 'a' variable to be the first title element node
- Set 'b' variable to remove the text node.
- Remove the element node by using the removeChild() method
We define to clear a text node
The removeChild() method is also be used to clear a text node:
<!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];
document.write("Value: " + a.nodeValue);
document.write("<br />");
a.nodeValue = "";
document.write("Value: " + a.nodeValue);
</script>
</body>
</html>
|
Define the code
- "loadxmldoc.html" get the data.
- Set 'a' variable to be the first title element node
- nodeValue property to clear the text node.
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