Exemplo n.º 1
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);
		}
	}
}
Exemplo n.º 2
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;
}