May 27, 2021 XML DOM
4. Delete yourself - Delete the current node
8.. Delete the property node by name
The removeChild() method removes the specified node.
The removeAttribute() method removes the specified property.
The following example uses the XML
file .xml.
The
function loadXMLDoc(),
located in an external JavaScript, is used to load XML files.
Remove the element node
In this example, removeChild() is used to remove the first element.
Delete the current element node
In this example, parentNode and removeChild() are used to remove the current element.
Delete the text node
In this example, removeChild() is used to remove the text node of the first element.
Empty the text of the text node
This example uses the nodeValue() property to empty the text node of the first element.
Delete the property by name
This example uses removeAttribute() to remove the "category" property from the first element.
Delete properties based on objects
This example uses removeAttributeNode() to remove all properties from all the elements.
The removeChild() method removes the specified node.
When a node is deleted, all of its child nodes are also deleted.
The following snippet will remove the first element from the loaded xml:
Example explanation:
The removeChild() method is the only way to remove the specified node.
When you have navigated to a node that needs to be deleted, you can delete it by using the parentNode property and the removeChild() method:
Example explanation:
The removeChild() method can be used to remove text nodes:
Example explanation:
Less commonly used removeChild() removes text from nodes. Y ou can use the nodeValue property instead of it. Look at the next paragraph.
The nodeValue property can be used to change or empty the value of a text node:
Example explanation:
Traversing and changing the text nodes of all the elements:
Try
The removeAttribute (name) method is used to remove property nodes by name.
Example: removeAttribute ('category')
The following snippet removes the "category" property from the first element:
Example explanation:
Traversing and deleting the "category" property of all the elements: Try
The removeAttributeNode (node) method removes the property node by using the node object as an argument.
Example: removeAttributeNode (x)
The following snippet removes all the properties of all the elements:
Example explanation: