Insert the node newChild before the existing child node refChild. If refChild is null, insert newChild at the end og the child's list. If newChild is an object DocumentFragment, all its childs are inserted, in the same order, before the refChild. If the newChild already exist in the tree is deleted.
 

1 dom.node.insertBefore

<dom.node.insertBefore>
    <newChild /> !
    <refChild /> !
</dom.node.insertBefore>

Exceptions

HIERARCHY_REQUEST_ERR

Appears if this node is of a type that not allow childs of the newChild node, if the type of the node to put is one of the ancestors of the node itself or the node itself, also if the node is of the Document type ans the result of the substitution operation adds a second DocumentType or Element in the Document node.

WRONG_DOCUMENT_ERR

Appears if newChild has been created of a different document than the one created by this node.

NO_MODIFICATION_ALLOWED_ERR

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

NOT_FOUND_ERR

Appears if refChild is not a child of this node.

NOT_SUPPORTED_ERR

If this node is of the Document type, this exception may appear if the DOM implementation does not support the replacement of the DocumentType child or Element child.

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, is necessary perform first a import of the node that will be added to decontextualize it, it means, unlink it of its owner document and in this way can use it in a different document. This operation should be performed when adding (dom.node.insertBefore), moving (dom.node.replaceChild) or inserting (dom.node.insertBefore).

Example

Inserting a node of a document below another node of a different document.

Copy
<xsql-script name='dom_node_insertBefore'>
    <body>
        <set name='root_ori'><dom.parse><file name='data1.xml' type='absolute' /></dom.parse></set>
        <set name='root_rpl'><dom.parse><file name='data2.xml' type='absolute' /></dom.parse></set>

        <!-- The node should be imported to unlink it of its                       -->
        <!-- owner document, and be able to use it in a new document.              -->
        <set name='node_rpl'>
            <dom.document.importNode>
                <root_ori/>
                <dom.node.getFirstChildElement><root_rpl/></dom.node.getFirstChildElement>
            </dom.document.importNode>
        </set>

        <!-- Replace the first element of the original document   -->
        <!-- with the node of the remplaced document.             -->
        <dom.node.insertBefore>
            <root_ori/>
            <node_rpl/>
            <dom.element.getFirstChildElement><root_ori /></dom.element.getFirstChildElement>
        </dom.node.insertBefore>
<!--
Returns:

<xsql-script name="print">
    <HOLA>
        <test/>
        <string>HELLO ECHO</string>
    </HOLA>
    <body>

        <println>
            <socket.print host="dbsrv1" port="7301">
            <string>HELLO ECHO</string></socket.print>
        </println>

    </body>
    </xsql-script>
-->
        <println>
            <root_ori/>
        </println>

    </body>
</xsql-script>