Exemple #1
0
void
DOM_Element_setAttribute(DOM_Element *element,
										const DOM_String *name, const DOM_String *value)
{
	if (element && name && value && element->attributes) {
		DOM_Attr *attr;

		attr = DOM_NamedNodeMap_getNamedItem(element->attributes, name);
		if (attr) {
			free(attr->nodeValue);
			attr->nodeValue = attr->u.Attr.value = DOM_String_dup(value);
			if (attr->nodeValue) {
			} else {
				DOM_Exception = DOM_NO_MEMORY_ERR;
				DOM_Document_destroyNode(attr->ownerDocument, attr);
			}
		} else {
			attr = DOM_Document_createAttribute(element->ownerDocument, name);
			if (attr) {
				free(attr->nodeValue);
				attr->nodeValue = attr->u.Attr.value = DOM_String_dup(value);
				if (attr->nodeValue) {
					DOM_NamedNodeMap_setNamedItem(element->attributes, attr);
				} else {
					DOM_Exception = DOM_NO_MEMORY_ERR;
					DOM_Document_destroyNode(attr->ownerDocument, attr);
				}
			}
		}
	}
}
Exemple #2
0
DOM_Node *
Document_createNode(DOM_Document *doc, unsigned short nodeType)
{
    DOM_Node *node;

	if (nodeType != DOM_DOCUMENT_NODE && doc == NULL) {
		DOM_Exception = DOM_NULL_POINTER_ERR;
		return NULL;
	}

    node = calloc(sizeof *node, 1);
    if (node == NULL) {
		DOM_Exception = DOM_NO_MEMORY_ERR;
		return NULL;
	}

    node->nodeType = nodeType;
    node->ownerDocument = doc;
    switch (nodeType) {
        case DOM_DOCUMENT_NODE:
			node->ownerDocument = node;
        case DOM_ELEMENT_NODE:
        case DOM_ATTRIBUTE_NODE:
        case DOM_ENTITY_REFERENCE_NODE:
        case DOM_ENTITY_NODE:
        case DOM_DOCUMENT_FRAGMENT_NODE:
            node->childNodes = Document_createNodeList(doc);
            if (node->childNodes == NULL) {
                DOM_Document_destroyNode(doc, node);
                return NULL;
            }
    }

    return node;
}
Exemple #3
0
void
DOM_Element_normalize(DOM_Element *element)
{
	DOM_Node *node;
	DOM_Text *last = NULL;

	if (element) {
		for (node = element->firstChild; node != NULL; node = node->nextSibling) {
			if (node->nodeType == DOM_TEXT_NODE) {
				if (last) {
					DOM_CharacterData_insertData(node, 0, last->nodeValue);
					DOM_Node_removeChild(element, last);
					DOM_Document_destroyNode(last->ownerDocument, last);
					if (DOM_Exception) {
						return;
					}
				}
				last = node;
			} else {
				last = NULL;
				DOM_Element_normalize(node);
			}
		}
	}
}
Exemple #4
0
void
chardata_fn(void *userData, const XML_Char *s, int len)
{
	struct stack *stk = (struct stack *) userData;
	DOM_String *str;
	DOM_Text *tex;
	DOM_Node *parent;

	if (stk == NULL || s == NULL || len == 0) {
		DOM_Exception = DOM_NULL_POINTER_ERR;
		return;
	}

	parent = (DOM_Node *) stack_peek(stk);
	if (parent == NULL) {
		DOM_Exception = DOM_SYSTEM_ERR;
		return;
	}
	if ((str = (DOM_String *) malloc(len + 1)) == NULL) {
		DOM_Exception = DOM_NO_MEMORY_ERR;
		return;
	}
	memcpy(str, s, len);
	str[len] = '\0';
	tex = DOM_Document_createTextNode(parent->ownerDocument, str);
	free(str);
	if (tex == NULL) {
		return;
	}

	DOM_Node_appendChild(parent, tex);
	if (DOM_Exception) {
		DOM_Document_destroyNode(parent->ownerDocument, tex);
	}
}
Exemple #5
0
void
DOM_Element_removeAttribute(DOM_Element *element, const DOM_String *name)
{
	if (element && name) {
		DOM_Attr *attr = DOM_NamedNodeMap_removeNamedItem(element->attributes, name);
		if (attr) {
			DOM_Document_destroyNode(attr->ownerDocument, attr);
		}
	}
}
Exemple #6
0
DOM_Attr *
DOM_Document_createAttribute(DOM_Document *doc, const DOM_String *name)
{
    DOM_Attr *attr;

    attr = Document_createNode(doc, DOM_ATTRIBUTE_NODE);
    if (attr) {
        attr->nodeName = attr->u.Attr.name = DOM_String_dup(name);
        attr->nodeValue = attr->u.Attr.value = DOM_String_dup("");
        if (attr->nodeName == NULL || attr->nodeValue == NULL) {
			DOM_Exception = DOM_NO_MEMORY_ERR;
            DOM_Document_destroyNode(doc, attr);
            return NULL;
        }
    }

    return attr;
}
Exemple #7
0
DOM_Element *
DOM_Document_createElement(DOM_Document *doc, const DOM_String *tagName)
{
    DOM_Element *element;

    element = Document_createNode(doc, DOM_ELEMENT_NODE);
    if (element) {
        element->nodeName = element->u.Element.tagName = DOM_String_dup(tagName);
		element->attributes = Document_createNamedNodeMap(doc);
		if (element->nodeName == NULL || element->attributes == NULL) {
			DOM_Exception = DOM_NO_MEMORY_ERR;
			DOM_Document_destroyNode(doc, element);
			return NULL;
		}
    }

    return element;
}
Exemple #8
0
void
DOM_Document_destroyNodeList(DOM_Document *doc, DOM_NodeList *nl, int free_nodes)
{
	if (nl) {
		NodeEntry *e, *tmp;

		e = nl->first;
		while (e != NULL) {
			if (free_nodes) {
				DOM_Document_destroyNode(doc, e->node);
			}
			tmp = e;
			e = e->next;
			free(tmp); 
		}
		free(nl);
	}
}
Exemple #9
0
DOM_ProcessingInstruction *
DOM_Document_createProcessingInstruction(DOM_Document *doc,
                                         const DOM_String *target, const DOM_String *data)
{
    DOM_ProcessingInstruction *pi;

    pi = Document_createNode(doc, DOM_PROCESSING_INSTRUCTION_NODE);
    if (pi) {
        pi->nodeName = pi->u.ProcessingInstruction.target = DOM_String_dup(target);
        pi->nodeValue = pi->u.ProcessingInstruction.data = DOM_String_dup(data);
        if (pi->nodeName == NULL || pi->nodeValue == NULL) {
			DOM_Exception = DOM_NO_MEMORY_ERR;
            DOM_Document_destroyNode(doc, pi);
            return NULL;
        }
    }

    return pi;
}
Exemple #10
0
DOM_CDATASection *
DOM_Document_createCDATASection(DOM_Document *doc, const DOM_String *data)
{
    DOM_CDATASection *cdata;

    cdata = Document_createNode(doc, DOM_CDATA_SECTION_NODE);
    if (cdata) {
        cdata->nodeName = "#cdata-section";
        cdata->nodeValue = cdata->u.CharacterData.data = DOM_String_dup(data);
        if (cdata->u.CharacterData.data == NULL) {
			DOM_Exception = DOM_NO_MEMORY_ERR;
            DOM_Document_destroyNode(doc, cdata);
            return NULL;
        }
        cdata->u.CharacterData.length = (unsigned long) DOM_String_len(data);
    }

    return cdata;
}
Exemple #11
0
DOM_Comment *
DOM_Document_createComment(DOM_Document *doc, const DOM_String *data)
{
    DOM_Comment *comment;

    comment = Document_createNode(doc, DOM_COMMENT_NODE);
    if (comment) {
        comment->nodeName = "#comment";
        comment->nodeValue = comment->u.CharacterData.data = DOM_String_dup(data);
        if (comment->nodeValue == NULL) {
			DOM_Exception = DOM_NO_MEMORY_ERR;
            DOM_Document_destroyNode(doc, comment);
            return NULL;
        }
        comment->u.CharacterData.length = (unsigned long) DOM_String_len(data);
    }

    return comment;
}
Exemple #12
0
DOM_Text *
DOM_Document_createTextNode(DOM_Document *doc, const DOM_String *data)
{
    DOM_Text *text;

    text = Document_createNode(doc, DOM_TEXT_NODE);
    if (text) {
        text->nodeName = "#text";
        text->nodeValue = text->u.CharacterData.data = DOM_String_dup(data);
        if (text->nodeValue == NULL) {
			DOM_Exception = DOM_NO_MEMORY_ERR;
            DOM_Document_destroyNode(doc, text);
            return NULL;
        }
        text->u.CharacterData.length = (unsigned long) DOM_String_len(data);
    }

    return text;
}
Exemple #13
0
void
processing_fn(void *userData, const XML_Char *target, const XML_Char *data)
{
	struct stack *stk = (struct stack *) userData;
	DOM_ProcessingInstruction *pi;
	DOM_Node *parent;

	parent = (DOM_Node *) stack_peek(stk);
	if (parent == NULL) {
		DOM_Exception = DOM_SYSTEM_ERR;
		return;
	}
	if ((pi = DOM_Document_createProcessingInstruction(parent->ownerDocument, target, data))) {
		DOM_Node_appendChild(parent, pi);
		if (DOM_Exception) {
			DOM_Document_destroyNode(parent->ownerDocument, pi);
		}
	}
}
Exemple #14
0
void
comment_fn(void *userData, const XML_Char *s)
{
	struct stack *stk = (struct stack *) userData;
	DOM_Comment *com;
	DOM_Node *parent;

	parent = (DOM_Node *) stack_peek(stk);
	if (parent == NULL) {
		DOM_Exception = DOM_SYSTEM_ERR;
		return;
	}
	if ((com = DOM_Document_createComment(parent->ownerDocument, s))) {
		DOM_Node_appendChild(parent, com);
		if (DOM_Exception) {
			DOM_Document_destroyNode(parent->ownerDocument, com);
		}
	}
}
Exemple #15
0
Calibration *createCalibration(char *CalFilePath,unsigned short index) {
// This function creates and populate a Calibration structure from a file.
	Calibration *cal;
	DOM_DocumentLS *doc;            // contains DOM document of calibration file
	DOM_Element *eRoot;             // points to document root element ("FTSensor")
	DOM_Node *node;                 // multipurpose variable for nodes in the cal file
	DOM_Element *eCalibration;      // points to Calibration element
	DOM_NodeList *calibrationNodelist;         //node lists in the cal file
	DOM_NodeList *axisNodelist;
	DOM_NodeList *childNodelist;
	char *temp;                     // temporary string value for reading in attributes
	unsigned short i,j;             // counter variables
	float temparray[MAX_GAUGES];    // used when loading calibration rows
	float scale;                    // used when loading calibration rows
	
	cal=(Calibration *) calloc(1,sizeof(Calibration));	
	doc = DOM_Implementation_createDocument(NULL, NULL, NULL);  // initialize DOM document	
	if (DOM_DocumentLS_load(doc,CalFilePath)!=1) {              // open calibration file
		free(cal);
		DOM_Document_destroyNode(doc, doc);    // clean up DOM stuff
		return NULL;
	}
	eRoot=doc->u.Document.documentElement;
	if (strcmp(eRoot->nodeName,"FTSensor")!=0) {        // make sure we're loading the right kind of file
		free(cal);
		DOM_Document_destroyNode(doc, doc);    // clean up DOM stuff
		return NULL;
	}

	ReadAttribute(eRoot,&temp,"Serial",TRUE,"");
	cal->Serial=ATI_strdup(temp);
	free(temp);
	ReadAttribute(eRoot,&temp,"BodyStyle",TRUE,"");
	cal->BodyStyle=ATI_strdup(temp);
	free(temp);
	ReadAttribute(eRoot,&temp,"NumGages",TRUE,"");
	cal->rt.NumChannels=atoi(temp)+1;	// add one to NumGages for the temperature channel.
	free(temp);
	ReadAttribute(eRoot,&temp,"Family",TRUE,"");
	cal->Family=ATI_strdup(temp);
	free(temp);
	// find calibration specified by index
	calibrationNodelist=DOM_Element_getElementsByTagName(eRoot,"Calibration");
	if (calibrationNodelist->length<index) {    // determine if invalid calibration index was used
		return NULL;
	}
	eCalibration=DOM_NodeList_item(calibrationNodelist,index-1);	
	
	// set Calibration structure attributes found in Calibration element
	ReadAttribute(eCalibration,&temp,"PartNumber",TRUE,"");
	cal->PartNumber=ATI_strdup(temp);
	free(temp);
	ReadAttribute(eCalibration,&temp,"CalDate",TRUE,"");
	cal->CalDate=ATI_strdup(temp);
	free(temp);
	ReadAttribute(eCalibration,&temp,"ForceUnits",TRUE,"");
	cal->ForceUnits=ATI_strdup(temp);
	free(temp);
	ReadAttribute(eCalibration,&temp,"TorqueUnits",TRUE,"");
	cal->TorqueUnits=ATI_strdup(temp);
	free(temp);
	ReadAttribute(eCalibration,&temp,"DistUnits",TRUE,"");
	cal->BasicTransform.DistUnits=ATI_strdup(temp);
	cal->cfg.UserTransform.DistUnits=ATI_strdup(temp);
	free(temp);
	ReadAttribute(eCalibration,&temp,"AngleUnits",FALSE,"degrees");
	cal->BasicTransform.AngleUnits=ATI_strdup(temp);
	cal->cfg.UserTransform.AngleUnits=ATI_strdup(temp);
	free(temp);
	// initialize temp comp variables
	cal->TempCompAvailable=FALSE;
	for (i=0;i<MAX_GAUGES;i++) {
		cal->rt.bias_slopes[i]=0;
		cal->rt.gain_slopes[i]=0;
	}
	cal->rt.thermistor=0;
	
	// store basic matrix
	axisNodelist=DOM_Element_getElementsByTagName(eCalibration,"Axis");

	cal->rt.NumAxes=(unsigned short) axisNodelist->length;
	for (i=0;i<axisNodelist->length;i++) {
		node=DOM_NodeList_item(axisNodelist,i);		
		ReadAttribute(node, &temp, "scale", FALSE,"1");
		scale=(float) atof(temp);
		free(temp);
		ReadAttribute(node, &temp, "values", TRUE,"");
		Separate(temp,temparray,(unsigned short)(cal->rt.NumChannels-1));
		for(j=0;j<cal->rt.NumChannels-1;j++) {
			cal->BasicMatrix[i][j]=temparray[j]/scale;
		}
		free(temp);
		ReadAttribute(node, &temp, "max", FALSE,"0");
		cal->MaxLoads[i]=(float) atof(temp);
		free(temp);		
		ReadAttribute(node, &temp, "Name", TRUE,"");
		cal->AxisNames[i]=ATI_strdup(temp);
		free(temp);
	}
    childNodelist=eCalibration->childNodes;
	for (i=0; i < childNodelist->length; i++) {
		node=DOM_NodeList_item(childNodelist,i);

		if (strcmp(node->nodeName,"BasicTransform")==0) {
			ReadAttribute(node, &temp, "Dx", FALSE,"0");
            cal->BasicTransform.TT[0]=(float) atof(temp);
			free(temp);
            ReadAttribute(node, &temp, "Dy", FALSE,"0");
            cal->BasicTransform.TT[1]=(float) atof(temp);
			free(temp);
			ReadAttribute(node, &temp, "Dz", FALSE,"0");
            cal->BasicTransform.TT[2]=(float) atof(temp);
			free(temp);
			ReadAttribute(node, &temp, "Rx", FALSE,"0");
            cal->BasicTransform.TT[3]=(float) atof(temp);
			free(temp);
			ReadAttribute(node, &temp, "Ry", FALSE,"0");
            cal->BasicTransform.TT[4]=(float) atof(temp);
			free(temp);
			ReadAttribute(node, &temp, "Rz", FALSE,"0");
            cal->BasicTransform.TT[5]=(float) atof(temp);
			free(temp);
		} else if (strcmp(node->nodeName,"BiasSlope")==0) {
			ReadAttribute(node, &temp, "values", TRUE,"");
            Separate(temp,cal->rt.bias_slopes,(unsigned short)(cal->rt.NumChannels-1));
			free(temp);
            cal->TempCompAvailable = TRUE;
		} else if (strcmp(node->nodeName,"GainSlope")==0) {
			ReadAttribute(node, &temp, "values", TRUE,"");
            Separate(temp,cal->rt.gain_slopes,(unsigned short)(cal->rt.NumChannels-1));
			free(temp);
            cal->TempCompAvailable = TRUE;
		} else if (strcmp(node->nodeName,"Thermistor")==0) {
            ReadAttribute(node, &temp, "value", TRUE,"");
			cal->rt.thermistor = (float) atof(temp);
			free(temp);
		}

	}

	DOM_Document_destroyNodeList(eRoot->ownerDocument, calibrationNodelist,0);
	DOM_Document_destroyNodeList(eRoot->ownerDocument, axisNodelist,0);	
	DOM_Document_destroyNode(doc, doc);    // clean up DOM stuff		
	ResetDefaults(cal);                    // calculate working matrix and set default values		
	return cal;	
} // createCalibration();
Exemple #16
0
DOM_Node *
DOM_Node_cloneNode(DOM_Node *node, int deep)
{
    DOM_Node *clone = NULL;
	DOM_Node *ntmp, *ctmp;
	NodeEntry *e;

	if (node == NULL) {
		DOM_Exception = DOM_NULL_POINTER_ERR;
		return NULL;
	}

    switch(node->nodeType) {
        case DOM_ELEMENT_NODE:
			clone = DOM_Document_createElement(node->ownerDocument, node->nodeName);
			if (clone) {
				for (e = node->attributes->first; e != NULL; e = e->next) {
					if ((ctmp = DOM_Node_cloneNode(e->node, deep)) == NULL ||
										NodeList_append(clone->attributes, ctmp) == NULL) {
						DOM_Document_destroyNode(clone->ownerDocument, ctmp);
						DOM_Document_destroyNode(clone->ownerDocument, clone);
						return NULL;
					}
				}
			}
            break;
        case DOM_ATTRIBUTE_NODE:
			if ((clone = DOM_Document_createAttribute(node->ownerDocument, node->nodeName))) {
           		clone->u.Attr.specified = node->u.Attr.specified;
				free(clone->nodeValue);
           		clone->u.Attr.value = clone->nodeValue = DOM_String_dup(node->nodeValue);
				if (clone->u.Attr.value == NULL) {
					DOM_Exception = DOM_NO_MEMORY_ERR;
					return NULL;
				}
			}
            break;
		case DOM_COMMENT_NODE:
			clone = DOM_Document_createComment(node->ownerDocument, node->nodeValue);
			break;
		case DOM_TEXT_NODE:
			clone = DOM_Document_createTextNode(node->ownerDocument, node->nodeValue);
			break;
		case DOM_CDATA_SECTION_NODE:
			clone = DOM_Document_createCDATASection(node->ownerDocument, node->nodeValue);
			break;
        case DOM_DOCUMENT_NODE:
			clone = DOM_Implementation_createDocument(NULL, NULL, NULL);
			break;
		case DOM_DOCUMENT_FRAGMENT_NODE:
			clone = DOM_Document_createDocumentFragment(node->ownerDocument);
			break;
        case DOM_PROCESSING_INSTRUCTION_NODE:
			clone = DOM_Document_createProcessingInstruction(node->ownerDocument,
					node->u.ProcessingInstruction.target, node->u.ProcessingInstruction.data);
			break;
        case DOM_ENTITY_REFERENCE_NODE:
        case DOM_ENTITY_NODE:
        case DOM_DOCUMENT_TYPE_NODE:
        case DOM_NOTATION_NODE:
			DOM_Exception = DOM_NOT_SUPPORTED_ERR;
			return NULL;
    }

	if (clone && node->childNodes) {
		for (ntmp = node->firstChild; ntmp != NULL; ntmp = ntmp->nextSibling) {
			ctmp = DOM_Node_cloneNode(ntmp, deep);
			if (ctmp == NULL || DOM_Node_appendChild(clone, ctmp) == NULL) {
				DOM_Document_destroyNode(clone->ownerDocument, ctmp);
				DOM_Document_destroyNode(clone->ownerDocument, clone);
				return NULL;
			}
		}
	}


	//DBL: erase next line
	if (DOM_Node_hasChildNodes(node)) {}


    return clone;
}
Exemple #17
0
DOM_Node *
DOM_Node_appendChild(DOM_Node *node, DOM_Node *newChild)
{
	int addingDocumentElement;

    if (node == NULL || newChild == NULL) {
		DOM_Exception = DOM_NULL_POINTER_ERR;
        return NULL;
    }
	if (newChild->ownerDocument != node->ownerDocument) {
		DOM_Exception = DOM_WRONG_DOCUMENT_ERR;
		return NULL;
	}
	addingDocumentElement = node->nodeType == DOM_DOCUMENT_NODE &&
							newChild->nodeType == DOM_ELEMENT_NODE;
	if (CANNOT_HAVE_CHILDREN(node->nodeType) || Node_isAncestor(newChild, node) ||
							(addingDocumentElement && node->u.Document.documentElement)) {
		DOM_Exception = DOM_HIERARCHY_REQUEST_ERR;
		return NULL;
	}

	if (newChild->nodeType == DOM_DOCUMENT_FRAGMENT_NODE) {
		DOM_Node *n, *nxt;

		for (n = newChild->firstChild; n != NULL; n = nxt) {
			nxt = n->nextSibling;
			if (DOM_Node_removeChild(newChild, n) == NULL) {
				return NULL;
			}
			if (DOM_Node_appendChild(node, n) == NULL) {
				DOM_Document_destroyNode(n->ownerDocument, n);
				return NULL;
			}
		}
		return newChild;
	}

	DOM_Node_removeChild(node, newChild);

	if (NodeList_append(node->childNodes, newChild) == NULL) {
		return NULL;
	}

	if (node->firstChild == NULL) {
		node->firstChild = node->lastChild = newChild;
		newChild->previousSibling = NULL;
		newChild->nextSibling = NULL;
	} else {
		node->lastChild->nextSibling = newChild;
		newChild->previousSibling = node->lastChild;
		node->lastChild = newChild;
	}
    newChild->nextSibling = NULL;
    newChild->parentNode = node;

	if (addingDocumentElement) {
		node->u.Document.documentElement = newChild;
	}

    return newChild;
}
Exemple #18
0
DOM_Node *
DOM_Node_replaceChild(DOM_Node *node, DOM_Node *newChild, DOM_Node *oldChild)
{
	DOM_Node *tmp;
	int addingDocumentElement;

    if (node == NULL || newChild == NULL || oldChild == NULL) {
		DOM_Exception = DOM_NULL_POINTER_ERR;
		return NULL;
	}
	if (newChild->ownerDocument != node->ownerDocument ||
							oldChild->ownerDocument != node->ownerDocument) {
		DOM_Exception = DOM_WRONG_DOCUMENT_ERR;
		return NULL;
	}
	addingDocumentElement = node->nodeType == DOM_DOCUMENT_NODE &&
							newChild->nodeType == DOM_ELEMENT_NODE;
	if (oldChild->parentNode != node || Node_isAncestor(newChild, node) ||
							(addingDocumentElement && node->u.Document.documentElement &&
							oldChild->nodeType != DOM_ELEMENT_NODE)) {
		DOM_Exception = DOM_HIERARCHY_REQUEST_ERR;
        return NULL;
    }

	for (tmp = node->firstChild; tmp != NULL && tmp != oldChild; tmp = tmp->nextSibling) {
		;
	}
	if (tmp != oldChild) {
		DOM_Exception = DOM_NOT_FOUND_ERR;
		return NULL;
	}

	if (newChild->nodeType == DOM_DOCUMENT_FRAGMENT_NODE) {
		DOM_Node *n, *nxt;

		for (n = newChild->firstChild; n != NULL; n = nxt) {
			nxt = n->nextSibling;
			if (DOM_Node_removeChild(newChild, n) == NULL) {
				return NULL;
			}
			if (DOM_Node_insertBefore(node, n, oldChild) == NULL) {
				DOM_Document_destroyNode(n->ownerDocument, n);
				return NULL;
			}
		}

		if (DOM_Node_removeChild(node, oldChild) == NULL) {
			return NULL;
		}

		return oldChild;
	}

	DOM_Node_removeChild(node, newChild);

	if (NodeList_replace(node->childNodes, newChild, oldChild) == NULL) {
		return NULL;
	}

	node->firstChild = node->childNodes->first->node;
	node->lastChild = node->childNodes->last->node;

    if ((newChild->previousSibling = oldChild->previousSibling)) {
        newChild->previousSibling->nextSibling = newChild;
    }
    if ((newChild->nextSibling = oldChild->nextSibling)) {
        newChild->nextSibling->previousSibling = newChild;
    }

    newChild->parentNode = node;
    oldChild->parentNode = NULL;
    oldChild->previousSibling = NULL;
    oldChild->nextSibling = NULL;

	if (addingDocumentElement) {
		node->u.Document.documentElement = newChild;
	}

    return oldChild;
}