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

EXPORT_SPEC int ixmlNode_replaceChild ( IXML_Node nodeptr,
IXML_Node newChild,
IXML_Node oldChild,
IXML_Node **  returnNode 

Replaces an existing child Node with a new child Node in the list of children of a Node.

If newChild is already in the tree, it will first be removed. returnNode will contain the oldChild Node, appropriately removed from the tree (i.e. it will no longer have an owner document).

An integer representing one of the following:
  • IXML_SUCCESS: The operation completed successfully.
  • IXML_INVALID_PARAMTER: Either nodeptr, newChild, or oldChild is NULL.
  • IXML_HIERARCHY_REQUEST_ERR: The newChild is not a type of Node that can be inserted into this tree or newChild is an ancestor of nodePtr.
  • IXML_WRONG_DOCUMENT_ERR: newChild was created from a different document than nodeptr.
  • IXML_NO_MODIFICATION_ALLOWED_ERR: nodeptr or its parent is read-only.
  • IXML_NOT_FOUND_ERR: oldChild is not a child of nodeptr.
nodeptr  [in] The parent of the Node which contains the child to replace.
newChild  [in] The child with which to replace oldChild.
oldChild  [in] The child to replace with newChild.
returnNode  [out] Pointer to a Node to place the removed oldChild Node.

Definition at line 525 of file node.c.

References ixmlNode_allowChildren(), ixmlNode_insertBefore(), ixmlNode_isAncestor(), ixmlNode_isParent(), ixmlNode_removeChild(), and _IXML_Node::ownerDocument.

      int ret = IXML_SUCCESS;

      if (nodeptr == NULL || newChild == NULL || oldChild == NULL) {
            return IXML_INVALID_PARAMETER;
      /* if nodetype of nodeptr does not allow children of the type of newChild
       * needs to add later or if newChild is one of nodeptr's ancestors */
      if (ixmlNode_isAncestor(newChild, nodeptr) == TRUE) {
            return IXML_HIERARCHY_REQUEST_ERR;

      if (ixmlNode_allowChildren(nodeptr, newChild) == FALSE) {
            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, oldChild) != TRUE) {
            return IXML_NOT_FOUND_ERR;

      ret = ixmlNode_insertBefore(nodeptr, newChild, oldChild);
      if (ret != IXML_SUCCESS) {
            return ret;

      ret = ixmlNode_removeChild(nodeptr, oldChild, returnNode);
      return ret;

Generated by  Doxygen 1.6.0   Back to index