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

EXPORT_SPEC int ixmlNode_appendChild ( IXML_Node nodeptr,
IXML_Node newChild 

Appends a child Node to the list of children of a Node.

If newChild is already in the tree, it is removed first.

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: newChild is of a type that cannot be added as a child of nodeptr 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 is a read-only Node.
nodeptr  [in] The Node in which to append the new child.
newChild  [in] The new child to append.

Definition at line 597 of file node.c.

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

Referenced by addToAction(), ixmlNode_insertBefore(), makeAction(), Parser_parseDocument(), and Parser_processElementName().

      IXML_Node *prev = NULL;
      IXML_Node *next = NULL;

      if (nodeptr == NULL || newChild == NULL) {
            return IXML_INVALID_PARAMETER;
      /* if newChild was created from a different document */
      if (newChild->ownerDocument != NULL &&
          nodeptr->ownerDocument != newChild->ownerDocument) {
            return IXML_WRONG_DOCUMENT_ERR;
      /* if newChild is an ancestor of nodeptr */
      if (ixmlNode_isAncestor(newChild, nodeptr) == TRUE) {
            return IXML_HIERARCHY_REQUEST_ERR;
      /* if nodeptr does not allow to have newChild as children */
      if (ixmlNode_allowChildren(nodeptr, newChild) == FALSE) {
            return IXML_HIERARCHY_REQUEST_ERR;

      if (ixmlNode_isParent(nodeptr, newChild) == TRUE ) {
            ixmlNode_removeChild(nodeptr, newChild, NULL);
      /* set the parent node pointer */
      newChild->parentNode = nodeptr;
      newChild->ownerDocument = nodeptr->ownerDocument;

      /* if the first child */
      if (nodeptr->firstChild == NULL) {
            nodeptr->firstChild = newChild;
      } else {
            prev = nodeptr->firstChild;
            next = prev->nextSibling;
            while (next != NULL) {
                  prev = next;
                  next = prev->nextSibling;
            prev->nextSibling = newChild;
            newChild->prevSibling = prev;

      return IXML_SUCCESS;

Generated by  Doxygen 1.6.0   Back to index