ixml/src/node.c
static IXML_Node *ixmlNode_cloneNodeTreeRecursive(
	/*! [in] Node tree to clone. */
	IXML_Node *nodeptr,
	/*! [in] TRUE if you want to clone the tree. */
	BOOL deep)
{
	IXML_Node *newNode = NULL;
	IXML_Element *newElement = NULL;
	IXML_Attr *newAttr = NULL;
	IXML_CDATASection *newCDATA = NULL;
	IXML_Document *newDoc = NULL;
	IXML_Node *nextSib = NULL;

	if (nodeptr != NULL) {
		switch (nodeptr->nodeType) {
		case eELEMENT_NODE:
			newElement = ixmlNode_cloneElement((IXML_Element *)nodeptr);
			if (newElement == NULL)
				return NULL;
			newElement->n.firstAttr = ixmlNode_cloneNodeTreeRecursive(
				nodeptr->firstAttr, deep);
			if (deep) {
				newElement->n.firstChild =
					ixmlNode_cloneNodeTreeRecursive(nodeptr->firstChild, deep);
				if (newElement->n.firstChild != NULL) {
					newElement->n.firstChild->parentNode = (IXML_Node *)newElement;
					ixmlNode_setSiblingNodesParent(newElement->n.firstChild);
				}
				nextSib = ixmlNode_cloneNodeTreeRecursive(nodeptr->nextSibling, deep);
				newElement->n.nextSibling = nextSib;
				if (nextSib != NULL) {
					nextSib->prevSibling = (IXML_Node *)newElement;
				}
			}
			newNode = (IXML_Node *)newElement;
			break;

		case eATTRIBUTE_NODE:
			newAttr = ixmlNode_cloneAttr((IXML_Attr *)nodeptr);
			if (newAttr == NULL)
				return NULL;
			nextSib = ixmlNode_cloneNodeTreeRecursive(nodeptr->nextSibling, deep);
			newAttr->n.nextSibling = nextSib;
			if (nextSib != NULL) {
				nextSib->prevSibling = (IXML_Node *)newAttr;
			}
			newNode = (IXML_Node *)newAttr;
			break;

		case eTEXT_NODE:
			newNode = ixmlNode_cloneTextNode(nodeptr);
			break;

		case eCDATA_SECTION_NODE:
			newCDATA = ixmlNode_cloneCDATASect((IXML_CDATASection *)nodeptr);
			newNode = (IXML_Node *)newCDATA;
			break;

		case eDOCUMENT_NODE:
			newDoc = ixmlNode_newDoc();
			if (newDoc == NULL)
				return NULL;
			newNode = (IXML_Node *)newDoc;
			if (deep) {
				newNode->firstChild = ixmlNode_cloneNodeTreeRecursive(
					nodeptr->firstChild, deep);
				if (newNode->firstChild != NULL) {
					newNode->firstChild->parentNode = newNode;
				}
			}
			break;

		case eINVALID_NODE:
		case eENTITY_REFERENCE_NODE:
		case eENTITY_NODE:
		case ePROCESSING_INSTRUCTION_NODE:
		case eCOMMENT_NODE:
		case eDOCUMENT_TYPE_NODE:
		case eDOCUMENT_FRAGMENT_NODE:
		case eNOTATION_NODE:
			break;
		}
	}

	return newNode;
}
/*!
 * \brief Recursive function that clones a node tree of nodeptr.
 *
 * \returns The cloned node/tree.
 */
\brief Recursive function that clones a node tree of nodeptr.
\returns The cloned node/tree.
\ brief Recursive function that clones a node tree of nodeptr . \ returns The cloned node / tree .
static IXML_Node *ixmlNode_cloneNodeTreeRecursive(
	IXML_Node *nodeptr,
	BOOL deep)
{
	IXML_Node *newNode = NULL;
	IXML_Element *newElement = NULL;
	IXML_Attr *newAttr = NULL;
	IXML_CDATASection *newCDATA = NULL;
	IXML_Document *newDoc = NULL;
	IXML_Node *nextSib = NULL;
	if (nodeptr != NULL) {
		switch (nodeptr->nodeType) {
		case eELEMENT_NODE:
			newElement = ixmlNode_cloneElement((IXML_Element *)nodeptr);
			if (newElement == NULL)
				return NULL;
			newElement->n.firstAttr = ixmlNode_cloneNodeTreeRecursive(
				nodeptr->firstAttr, deep);
			if (deep) {
				newElement->n.firstChild =
					ixmlNode_cloneNodeTreeRecursive(nodeptr->firstChild, deep);
				if (newElement->n.firstChild != NULL) {
					newElement->n.firstChild->parentNode = (IXML_Node *)newElement;
					ixmlNode_setSiblingNodesParent(newElement->n.firstChild);
				}
				nextSib = ixmlNode_cloneNodeTreeRecursive(nodeptr->nextSibling, deep);
				newElement->n.nextSibling = nextSib;
				if (nextSib != NULL) {
					nextSib->prevSibling = (IXML_Node *)newElement;
				}
			}
			newNode = (IXML_Node *)newElement;
			break;
		case eATTRIBUTE_NODE:
			newAttr = ixmlNode_cloneAttr((IXML_Attr *)nodeptr);
			if (newAttr == NULL)
				return NULL;
			nextSib = ixmlNode_cloneNodeTreeRecursive(nodeptr->nextSibling, deep);
			newAttr->n.nextSibling = nextSib;
			if (nextSib != NULL) {
				nextSib->prevSibling = (IXML_Node *)newAttr;
			}
			newNode = (IXML_Node *)newAttr;
			break;
		case eTEXT_NODE:
			newNode = ixmlNode_cloneTextNode(nodeptr);
			break;
		case eCDATA_SECTION_NODE:
			newCDATA = ixmlNode_cloneCDATASect((IXML_CDATASection *)nodeptr);
			newNode = (IXML_Node *)newCDATA;
			break;
		case eDOCUMENT_NODE:
			newDoc = ixmlNode_newDoc();
			if (newDoc == NULL)
				return NULL;
			newNode = (IXML_Node *)newDoc;
			if (deep) {
				newNode->firstChild = ixmlNode_cloneNodeTreeRecursive(
					nodeptr->firstChild, deep);
				if (newNode->firstChild != NULL) {
					newNode->firstChild->parentNode = newNode;
				}
			}
			break;
		case eINVALID_NODE:
		case eENTITY_REFERENCE_NODE:
		case eENTITY_NODE:
		case ePROCESSING_INSTRUCTION_NODE:
		case eCOMMENT_NODE:
		case eDOCUMENT_TYPE_NODE:
		case eDOCUMENT_FRAGMENT_NODE:
		case eNOTATION_NODE:
			break;
		}
	}
	return newNode;
}
static IXML_Node * ixmlNode_cloneNodeTreeRecursive ( IXML_Node * nodeptr , BOOL deep ) { IXML_Node * newNode = NULL ; IXML_Element * newElement = NULL ; IXML_Attr * newAttr = NULL ; IXML_CDATASection * newCDATA = NULL ; IXML_Document * newDoc = NULL ; IXML_Node * nextSib = NULL ; if ( nodeptr != NULL ) { switch ( nodeptr -> nodeType ) { case eELEMENT_NODE : newElement = ixmlNode_cloneElement ( ( IXML_Element * ) nodeptr ) ; if ( newElement == NULL ) return NULL ; newElement -> n . firstAttr = ixmlNode_cloneNodeTreeRecursive ( nodeptr -> firstAttr , deep ) ; if ( deep ) { newElement -> n . firstChild = ixmlNode_cloneNodeTreeRecursive ( nodeptr -> firstChild , deep ) ; if ( newElement -> n . firstChild != NULL ) { newElement -> n . firstChild -> parentNode = ( IXML_Node * ) newElement ; ixmlNode_setSiblingNodesParent ( newElement -> n . firstChild ) ; } nextSib = ixmlNode_cloneNodeTreeRecursive ( nodeptr -> nextSibling , deep ) ; newElement -> n . nextSibling = nextSib ; if ( nextSib != NULL ) { nextSib -> prevSibling = ( IXML_Node * ) newElement ; } } newNode = ( IXML_Node * ) newElement ; break ; case eATTRIBUTE_NODE : newAttr = ixmlNode_cloneAttr ( ( IXML_Attr * ) nodeptr ) ; if ( newAttr == NULL ) return NULL ; nextSib = ixmlNode_cloneNodeTreeRecursive ( nodeptr -> nextSibling , deep ) ; newAttr -> n . nextSibling = nextSib ; if ( nextSib != NULL ) { nextSib -> prevSibling = ( IXML_Node * ) newAttr ; } newNode = ( IXML_Node * ) newAttr ; break ; case eTEXT_NODE : newNode = ixmlNode_cloneTextNode ( nodeptr ) ; break ; case eCDATA_SECTION_NODE : newCDATA = ixmlNode_cloneCDATASect ( ( IXML_CDATASection * ) nodeptr ) ; newNode = ( IXML_Node * ) newCDATA ; break ; case eDOCUMENT_NODE : newDoc = ixmlNode_newDoc ( ) ; if ( newDoc == NULL ) return NULL ; newNode = ( IXML_Node * ) newDoc ; if ( deep ) { newNode -> firstChild = ixmlNode_cloneNodeTreeRecursive ( nodeptr -> firstChild , deep ) ; if ( newNode -> firstChild != NULL ) { newNode -> firstChild -> parentNode = newNode ; } } break ; case eINVALID_NODE : case eENTITY_REFERENCE_NODE : case eENTITY_NODE : case ePROCESSING_INSTRUCTION_NODE : case eCOMMENT_NODE : case eDOCUMENT_TYPE_NODE : case eDOCUMENT_FRAGMENT_NODE : case eNOTATION_NODE : break ; } } return newNode ; }
\brief Recursive function that clones a node tree of nodeptr.
\ brief Recursive function that clones a node tree of nodeptr .
/*! [in] Node tree to clone. */ /*! [in] TRUE if you want to clone the tree. */