diff options
Diffstat (limited to 'tree.c')
-rw-r--r-- | tree.c | 141 |
1 files changed, 111 insertions, 30 deletions
@@ -329,7 +329,7 @@ xmlSplitQName3(const xmlChar *name, int *len) { #define CUR_SCHAR(s, l) xmlStringCurrentChar(NULL, s, &l) -#if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) +#if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) || defined(LIBXML_DEBUG_ENABLED) /** * xmlValidateNCName: * @value: the value to check @@ -1119,6 +1119,10 @@ xmlFreeDoc(xmlDocPtr cur) { #endif return; } +#ifdef LIBXML_DEBUG_RUNTIME + xmlDebugCheckDocument(stderr, cur); +#endif + if (cur != NULL) dict = cur->dict; if ((__xmlRegisterCallbacks) && (xmlDeregisterNodeDefaultValue)) @@ -1302,6 +1306,7 @@ xmlStringLenGetNodeList(xmlDocPtr doc, const xmlChar *value, int len) { temp = ent->children; while (temp) { temp->parent = (xmlNodePtr)ent; + ent->last = temp; temp = temp->next; } } @@ -1744,7 +1749,10 @@ xmlNewProp(xmlNodePtr node, const xmlChar *name, const xmlChar *value) { doc = node->doc; cur->doc = doc; } - cur->name = xmlStrdup(name); + if ((doc != NULL) && (doc->dict != NULL)) + cur->name = (xmlChar *) xmlDictLookup(doc->dict, name, -1); + else + cur->name = xmlStrdup(name); if (value != NULL) { xmlChar *buffer; xmlNodePtr tmp; @@ -1825,7 +1833,10 @@ xmlNewNsProp(xmlNodePtr node, xmlNsPtr ns, const xmlChar *name, cur->doc = doc; } cur->ns = ns; - cur->name = xmlStrdup(name); + if ((doc != NULL) && (doc->dict != NULL)) + cur->name = xmlDictLookup(doc->dict, name, -1); + else + cur->name = xmlStrdup(name); if (value != NULL) { xmlChar *buffer; xmlNodePtr tmp; @@ -1974,7 +1985,10 @@ xmlNewDocProp(xmlDocPtr doc, const xmlChar *name, const xmlChar *value) { memset(cur, 0, sizeof(xmlAttr)); cur->type = XML_ATTRIBUTE_NODE; - cur->name = xmlStrdup(name); + if ((doc != NULL) && (doc->dict != NULL)) + cur->name = xmlDictLookup(doc->dict, name, -1); + else + cur->name = xmlStrdup(name); cur->doc = doc; if (value != NULL) { xmlNodePtr tmp; @@ -2093,7 +2107,8 @@ xmlRemoveProp(xmlAttrPtr cur) { #endif /* LIBXML_TREE_ENABLED */ /** - * xmlNewPI: + * xmlNewDocPI: + * @doc: the target document * @name: the processing instruction name * @content: the PI content * @@ -2101,7 +2116,7 @@ xmlRemoveProp(xmlAttrPtr cur) { * Returns a pointer to the new node object. */ xmlNodePtr -xmlNewPI(const xmlChar *name, const xmlChar *content) { +xmlNewDocPI(xmlDocPtr doc, const xmlChar *name, const xmlChar *content) { xmlNodePtr cur; if (name == NULL) { @@ -2123,7 +2138,10 @@ xmlNewPI(const xmlChar *name, const xmlChar *content) { memset(cur, 0, sizeof(xmlNode)); cur->type = XML_PI_NODE; - cur->name = xmlStrdup(name); + if ((doc != NULL) && (doc->dict != NULL)) + cur->name = xmlDictLookup(doc->dict, name, -1); + else + cur->name = xmlStrdup(name); if (content != NULL) { cur->content = xmlStrdup(content); } @@ -2134,6 +2152,21 @@ xmlNewPI(const xmlChar *name, const xmlChar *content) { } /** + * xmlNewPI: + * @name: the processing instruction name + * @content: the PI content + * + * Creation of a processing instruction element. + * Use xmlDocNewPI preferably to get string interning + * + * Returns a pointer to the new node object. + */ +xmlNodePtr +xmlNewPI(const xmlChar *name, const xmlChar *content) { + return(xmlNewDocPI(NULL, name, content)); +} + +/** * xmlNewNode: * @ns: namespace if any * @name: the node name @@ -2237,7 +2270,11 @@ xmlNewDocNode(xmlDocPtr doc, xmlNsPtr ns, const xmlChar *name, const xmlChar *content) { xmlNodePtr cur; - cur = xmlNewNode(ns, name); + if ((doc != NULL) && (doc->dict != NULL)) + cur = xmlNewNodeEatName(ns, (xmlChar *) + xmlDictLookup(doc->dict, name, -1)); + else + cur = xmlNewNode(ns, name); if (cur != NULL) { cur->doc = doc; if (content != NULL) { @@ -2299,7 +2336,7 @@ xmlNewDocRawNode(xmlDocPtr doc, xmlNsPtr ns, const xmlChar *name, const xmlChar *content) { xmlNodePtr cur; - cur = xmlNewNode(ns, name); + cur = xmlNewDocNode(doc, ns, name, NULL); if (cur != NULL) { cur->doc = doc; if (content != NULL) { @@ -3799,8 +3836,12 @@ xmlStaticCopyNode(const xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent, ret->name = xmlStringTextNoenc; else if (node->name == xmlStringComment) ret->name = xmlStringComment; - else if (node->name != NULL) - ret->name = xmlStrdup(node->name); + else if (node->name != NULL) { + if ((doc != NULL) && (doc->dict != NULL)) + ret->name = xmlDictLookup(doc->dict, node->name, -1); + else + ret->name = xmlStrdup(node->name); + } if ((node->type != XML_ELEMENT_NODE) && (node->content != NULL) && (node->type != XML_ENTITY_REF_NODE) && @@ -3964,10 +4005,25 @@ xmlDocCopyNode(const xmlNodePtr node, xmlDocPtr doc, int extended) { } /** + * xmlDocCopyNodeList: + * @doc: the target document + * @node: the first node in the list. + * + * Do a recursive copy of the node list. + * + * Returns: a new #xmlNodePtr, or NULL in case of error. + */ +xmlNodePtr xmlDocCopyNodeList(xmlDocPtr doc, const xmlNodePtr node) { + xmlNodePtr ret = xmlStaticCopyNodeList(node, doc, NULL); + return(ret); +} + +/** * xmlCopyNodeList: * @node: the first node in the list. * * Do a recursive copy of the node list. + * Use xmlDocCopyNodeList() if possible to ensure string interning. * * Returns: a new #xmlNodePtr, or NULL in case of error. */ @@ -4414,7 +4470,7 @@ xmlDocSetRootElement(xmlDocPtr doc, xmlNodePtr root) { if (root == NULL) return(NULL); xmlUnlinkNode(root); - root->doc = doc; + xmlSetTreeDoc(root, doc); root->parent = (xmlNodePtr) doc; old = doc->children; while (old != NULL) { @@ -5076,7 +5132,7 @@ xmlNodeSetContent(xmlNodePtr cur, const xmlChar *content) { case XML_COMMENT_NODE: if (cur->content != NULL) { if (!((cur->doc != NULL) && (cur->doc->dict != NULL) && - xmlDictOwns(cur->doc->dict, cur->content))) + (!xmlDictOwns(cur->doc->dict, cur->content)))) xmlFree(cur->content); } if (cur->children != NULL) xmlFreeNodeList(cur->children); @@ -5912,6 +5968,7 @@ xmlHasProp(xmlNodePtr node, const xmlChar *name) { * This does the entity substitution. * This function looks in DTD attribute declaration for #FIXED or * default declaration values unless DTD use has been turned off. + * Note that a namespace of NULL indicates to use the default namespace. * * Returns the attribute or the attribute declaration or NULL * if neither was found. @@ -5927,17 +5984,18 @@ xmlHasNsProp(xmlNodePtr node, const xmlChar *name, const xmlChar *nameSpace) { return(NULL); prop = node->properties; - if (nameSpace == NULL) - return(xmlHasProp(node, name)); while (prop != NULL) { /* * One need to have * - same attribute names * - and the attribute carrying that namespace */ - if ((xmlStrEqual(prop->name, name)) && - ((prop->ns != NULL) && (xmlStrEqual(prop->ns->href, nameSpace)))) { - return(prop); + if (xmlStrEqual(prop->name, name)) { + if (((prop->ns != NULL) && + (xmlStrEqual(prop->ns->href, nameSpace))) || + ((prop->ns == NULL) && (nameSpace == NULL))) { + return(prop); + } } prop = prop->next; } @@ -5970,16 +6028,25 @@ xmlHasNsProp(xmlNodePtr node, const xmlChar *name, const xmlChar *nameSpace) { return(NULL); } - cur = nsList; - while (*cur != NULL) { - if (xmlStrEqual((*cur)->href, nameSpace)) { - attrDecl = xmlGetDtdQAttrDesc(doc->intSubset, ename, - name, (*cur)->prefix); - if ((attrDecl == NULL) && (doc->extSubset != NULL)) - attrDecl = xmlGetDtdQAttrDesc(doc->extSubset, ename, + if (nameSpace == NULL) { + attrDecl = xmlGetDtdQAttrDesc(doc->intSubset, ename, + name, NULL); + if ((attrDecl == NULL) && (doc->extSubset != NULL)) { + attrDecl = xmlGetDtdQAttrDesc(doc->extSubset, ename, + name, NULL); + } + } else { + cur = nsList; + while (*cur != NULL) { + if (xmlStrEqual((*cur)->href, nameSpace)) { + attrDecl = xmlGetDtdQAttrDesc(doc->intSubset, ename, name, (*cur)->prefix); + if ((attrDecl == NULL) && (doc->extSubset != NULL)) + attrDecl = xmlGetDtdQAttrDesc(doc->extSubset, ename, + name, (*cur)->prefix); + } + cur++; } - cur++; } xmlFree(nsList); xmlFree(ename); @@ -6196,10 +6263,17 @@ xmlUnsetProp(xmlNodePtr node, const xmlChar *name) { while (prop != NULL) { if ((xmlStrEqual(prop->name, name)) && (prop->ns == NULL)) { - if (prev == NULL) + if (prev == NULL) { node->properties = prop->next; - else + if (prop->next != NULL) + prop->next->prev = NULL; + } else { prev->next = prop->next; + if (prop->next != NULL) + prop->next->prev = NULL; + } + prop->next = NULL; + prop->prev = NULL; xmlFreeProp(prop); return(0); } @@ -6231,10 +6305,17 @@ xmlUnsetNsProp(xmlNodePtr node, xmlNsPtr ns, const xmlChar *name) { while (prop != NULL) { if ((xmlStrEqual(prop->name, name)) && (prop->ns != NULL) && (xmlStrEqual(prop->ns->href, ns->href))) { - if (prev == NULL) + if (prev == NULL) { node->properties = prop->next; - else + if (prop->next != NULL) + prop->next->prev = NULL; + } else { prev->next = prop->next; + if (prop->next != NULL) + prop->next->prev = NULL; + } + prop->next = NULL; + prop->prev = NULL; xmlFreeProp(prop); return(0); } |