Calling insertBefore on Elements

MSXML 5.0 SDK

Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - DOM Reference

Calling insertBefore on Elements

If the current node is an element, calling insertBefore has the following results, depending on the value of the newChild parameter.

Node type passed in newChild Result
NODE_CDATA_SECTION, NODE_COMMENT, NODE_ELEMENT, NODE_ENTITY_REFERENCE, NODE_TEXT, NODE_PROCESSING_INSTRUCTION Inserts newChild and returns newChild.
NODE_ATTRIBUTE, NODE_DOCUMENT, NODE_DOCUMENT_TYPE, NODE_ENTITY, NODE_NOTATION Returns an error. These node types cannot be children of an element node.
NODE_DOCUMENT_FRAGMENT Inserts the children of the document fragment (newChild) and returns newChild.
NODE_ENTITY_REFERENCE Returns an error. Although the child nodes of an entity reference are the expanded entity, the children cannot be modified.

Remarks

When elements are added as children to other elements, they introduce their own namespace scoping. That is, if the element is from a default namespace, the default has scope beginning with the element being added.

If an entity reference is being added as a child to an element or document fragment, the namespace declaration of the entity reference is added to the containing element.