The DomNode class / om.DomNode methods |
Deletes the specified child node from the current node.
The removeChild() method detaches a om.DomNode element node from the current node.
The removed node is not destroyed, if it is still referenced by a variable: The removeChild() method will only break the link between the parent node and the child node. The child node still exists in the DOM document, but it is an orphan node, that can be attached to another parent node in the document.
MAIN DEFINE doc om.DomDocument, r om.DomNode, p om.DomNode, c om.DomNode LET doc = om.DomDocument.create("Items") LET r = doc.createElement("Zoo") LET p = doc.createElement("DodoList") CALL r.appendChild(p) LET c = doc.createElement("Dodo") CALL c.setAttribute("name", "momo") CALL c.setAttribute("gender", "male") CALL p.appendChild(c) CALL r.writeXml("file1.xml") CALL p.removeChild(c) -- c is orphan but still exists CALL c.writeXml("file2.xml") LET c = NULL -- unref/destroy the node CALL r.writeXml("file3.xml") END MAIN
The above program will produce the following files:
<?xml version='1.0' encoding='ASCII'?> <Zoo> <DodoList> <Dodo name="momo" gender="male"/> </DodoList> </Zoo>
<?xml version='1.0' encoding='ASCII'?> <Dodo name="momo" gender="male"/>
<?xml version='1.0' encoding='ASCII'?> <Zoo> <DodoList/> </Zoo>