ixml/src/node.c
static IXML_Node *ixmlNode_cloneNodeTree(
	/*! [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;
	IXML_Node *childNode;

	assert(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);
			childNode = newElement->n.firstChild;
			while (childNode != NULL) {
				childNode->parentNode = (IXML_Node *)newElement;
				childNode = childNode->nextSibling;
			}
			newElement->n.nextSibling = NULL;
		}
		newNode = ( IXML_Node * ) newElement;
		break;

	case eATTRIBUTE_NODE:
	case eTEXT_NODE:
	case eCDATA_SECTION_NODE:
	case eDOCUMENT_NODE:
		newNode = ixmlNode_cloneNodeTreeRecursive(nodeptr, deep);
		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:
#if 0
		/* create a new node here? */
		newNode = (IXML_Node *)malloc(sizeof(IXML_Node));
		if (newNode == NULL) {
			return NULL;
		}
#endif
		break;
	}

	/* by spec, the duplicate node has no parent */
	if (newNode != NULL)
		newNode->parentNode = NULL;

	return newNode;
}
/*!
 * \brief Function that clones a node tree of nodeptr.
 *
 * \returns The cloned node/tree.
 */
\brief Function that clones a node tree of nodeptr.
\returns The cloned node/tree.
\ brief Function that clones a node tree of nodeptr . \ returns The cloned node / tree .
static IXML_Node *ixmlNode_cloneNodeTree(
	IXML_Node *nodeptr,
	BOOL deep)
{
	IXML_Node *newNode = NULL;
	IXML_Element *newElement;
	IXML_Node *childNode;
	assert(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);
			childNode = newElement->n.firstChild;
			while (childNode != NULL) {
				childNode->parentNode = (IXML_Node *)newElement;
				childNode = childNode->nextSibling;
			}
			newElement->n.nextSibling = NULL;
		}
		newNode = ( IXML_Node * ) newElement;
		break;
	case eATTRIBUTE_NODE:
	case eTEXT_NODE:
	case eCDATA_SECTION_NODE:
	case eDOCUMENT_NODE:
		newNode = ixmlNode_cloneNodeTreeRecursive(nodeptr, deep);
		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:
#if 0
		newNode = (IXML_Node *)malloc(sizeof(IXML_Node));
		if (newNode == NULL) {
			return NULL;
		}
#endif
		break;
	}
	if (newNode != NULL)
		newNode->parentNode = NULL;
	return newNode;
}
static IXML_Node * ixmlNode_cloneNodeTree ( IXML_Node * nodeptr , BOOL deep ) { IXML_Node * newNode = NULL ; IXML_Element * newElement ; IXML_Node * childNode ; assert ( 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 ) ; childNode = newElement -> n . firstChild ; while ( childNode != NULL ) { childNode -> parentNode = ( IXML_Node * ) newElement ; childNode = childNode -> nextSibling ; } newElement -> n . nextSibling = NULL ; } newNode = ( IXML_Node * ) newElement ; break ; case eATTRIBUTE_NODE : case eTEXT_NODE : case eCDATA_SECTION_NODE : case eDOCUMENT_NODE : newNode = ixmlNode_cloneNodeTreeRecursive ( nodeptr , deep ) ; 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 : #if 0 newNode = ( IXML_Node * ) malloc ( sizeof ( IXML_Node ) ) ; if ( newNode == NULL ) { return NULL ; } #endif break ; } if ( newNode != NULL ) newNode -> parentNode = NULL ; return newNode ; }
\brief Function that clones a node tree of nodeptr.
\ brief Function that clones a node tree of nodeptr .
/*! [in] Node tree to clone. */ /*! [in] TRUE if you want to clone the tree. */ /* create a new node here? */ /* by spec, the duplicate node has no parent */