Logo Search packages:      
Sourcecode: libupnp4 version File versions  Download package

EXPORT_SPEC int ixmlNode_insertBefore ( IXML_Node nodeptr,
IXML_Node newChild,
IXML_Node refChild 
)

Inserts a new child Node before the existing child Node.

refChild can be NULL, which inserts newChild at the end of the list of children. Note that the Node (or Nodes) in newChild must already be owned by the owner document (or have no owner at all) of nodeptr for insertion. If not, the Node (or Nodes) must be imported into the document using ixmlDocument_importNode. If newChild is already in the tree, it is removed first.

Returns:
An integer representing one of the following:
  • IXML_SUCCESS: The operation completed successfully.
  • IXML_INVALID_PARAMETER: Either nodeptr or newChild is NULL.
  • IXML_HIERARCHY_REQUEST_ERR: The type of the Node does not allow children of the type of newChild.
  • IXML_WRONG_DOCUMENT_ERR: newChild has an owner document that does not match the owner of nodeptr.
  • IXML_NO_MODIFICATION_ALLOWED_ERR: nodeptr is read-only or the parent of the Node being inserted is read-only.
  • IXML_NOT_FOUND_ERR: refChild is not a child of nodeptr.
Parameters:
nodeptr  [in] The parent of the Node before which to insert the new child.
newChild  [in] The Node to insert into the tree.
refChild  [in] The reference child where the new Node should be inserted. The new Node will appear directly before the reference child.

Definition at line 474 of file node.c.

References _IXML_Node::firstChild, ixmlNode_allowChildren(), ixmlNode_appendChild(), ixmlNode_isAncestor(), ixmlNode_isParent(), ixmlNode_removeChild(), _IXML_Node::nextSibling, _IXML_Node::ownerDocument, _IXML_Node::parentNode, and _IXML_Node::prevSibling.

Referenced by ixmlNode_replaceChild().

{
      int ret = IXML_SUCCESS;

      if (nodeptr == NULL || newChild == NULL) {
            return IXML_INVALID_PARAMETER;
      }
      /* whether nodeptr allow children of the type of newChild */
      if (ixmlNode_allowChildren(nodeptr, newChild) == FALSE) {
            return IXML_HIERARCHY_REQUEST_ERR;
      }
      /* or if newChild is one of nodeptr's ancestors */
      if (ixmlNode_isAncestor(newChild, nodeptr) == TRUE) {
            return IXML_HIERARCHY_REQUEST_ERR;
      }
      /* if newChild was created from a different document */
      if (nodeptr->ownerDocument != newChild->ownerDocument) {
            return IXML_WRONG_DOCUMENT_ERR;
      }
      /* if refChild is not a child of nodeptr */
      if (ixmlNode_isParent(nodeptr, refChild) == FALSE) {
            return IXML_NOT_FOUND_ERR;
      }

      if (refChild != NULL) {
            if (ixmlNode_isParent(nodeptr, newChild) == TRUE) {
                  ixmlNode_removeChild(nodeptr, newChild, NULL);
                  newChild->nextSibling = NULL;
                  newChild->prevSibling = NULL;
            }
            newChild->nextSibling = refChild;
            if (refChild->prevSibling != NULL) {
                  refChild->prevSibling->nextSibling = newChild;
                  newChild->prevSibling = refChild->prevSibling;
            }
            refChild->prevSibling = newChild;
            if (newChild->prevSibling == NULL) {
                  nodeptr->firstChild = newChild;
            }
            newChild->parentNode = nodeptr;
      } else {
            ret = ixmlNode_appendChild( nodeptr, newChild );
      }

      return ret;
}


Generated by  Doxygen 1.6.0   Back to index