Adds a node at the end of the list of childs of the indicated node. If the node to add already exist in the tree, it will be deleted.

1 dom.appendChild

<dom.appendChild type='node|text|cdata|comment|element'>    <node /> !    <newChild /> !</dom.appendChild>

Exceptions

HIERARCHY_REQUEST_ERR

It appears if this node is of a type which does not allow childs of the typeof of the node newChild, or if the node to be added is one of the ancestors of this node.

WRONG_DOCUMENT_ERR

It appears if newChild has been created from a different file than the one that created this node.

NO_MODIFICATION_ALLOWED_ERR

It appears if this node is readonly or if the previous parent of the node being inserted is readonly.

Remarks

If the node to be added does not belong to the document to which the node in which it is to be added belongs, it is necessary to first make an import of the node to be added, in order to decontextualize it. This means, unlink it from its owner document and from this way to use it in a different document. This operation should be performed when it is added ( dom.node.insertBefore), is replaced ( dom.node.replaceChild) or is inserted ( dom.node.insertBefore).

Example

Add a node of a file to a different file.

Copy
<xsql-script name='dom_node_appendChild'>

<body>
<set name='root_ori'>
<dom.parse><file name='data1.xml' type='absolute' /></dom.parse>
</set>
<dom.parse><file name='data2.xml' type='absolute' /></dom.parse>
</set>

<!-- The node should be imported first, to unlink it from its                      -->
<!-- own file and be able to use it in a new document.                             -->
<!-- nodo node_add does not have own document and point to a node of the root_add. -->
<dom.document.importNode>
<root_ori/>
</dom.document.importNode>
</set>

<!--

<elem>text of node to import</elem>
-->

<println>----------------------------------------------------</println>
<println>
<dom.node.appendChild>
<root_ori/>
</dom.node.appendChild>
</println>

<!--
Returns the original file with the added node:

<document>
<element>hello</element>
<element>world</element>
<elem>text of node to import</elem>
</document>
-->

<println>Original file with the new added node:</println>
<println>----------------------------------------------------</println>
<println>
<root_ori/>
</println>

</body>
</xsql-script>