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); } }
DOM_Text * DOM_Text_splitText(DOM_Text *text, unsigned long offset) { DOM_Text *node; if (text && text->parentNode) { node = DOM_Document_createTextNode(text->ownerDocument, text->nodeValue + offset); if (node) { DOM_CharacterData_deleteData(text, offset, LONG_MAX); DOM_Node_insertBefore(text->parentNode, node, text->nextSibling); return node; } } return NULL; }
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; }