mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-10-21 14:53:44 +03:00
tree: Allocate XML namespace statically
This commit is contained in:
4
SAX2.c
4
SAX2.c
@@ -812,10 +812,6 @@ xmlSAX2StartDocument(void *ctx)
|
|||||||
doc->dict = ctxt->dict;
|
doc->dict = ctxt->dict;
|
||||||
xmlDictReference(doc->dict);
|
xmlDictReference(doc->dict);
|
||||||
}
|
}
|
||||||
if (xmlTreeEnsureXMLDecl(doc) == NULL) {
|
|
||||||
xmlSAX2ErrMemory(ctxt);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if ((ctxt->myDoc != NULL) && (ctxt->myDoc->URL == NULL) &&
|
if ((ctxt->myDoc != NULL) && (ctxt->myDoc->URL == NULL) &&
|
||||||
(ctxt->input != NULL) && (ctxt->input->filename != NULL)) {
|
(ctxt->input != NULL) && (ctxt->input->filename != NULL)) {
|
||||||
|
13
debugXML.c
13
debugXML.c
@@ -101,6 +101,10 @@ xmlNsCheckScope(xmlNodePtr node, xmlNsPtr ns)
|
|||||||
(node->type != XML_XINCLUDE_START))
|
(node->type != XML_XINCLUDE_START))
|
||||||
return(-2);
|
return(-2);
|
||||||
|
|
||||||
|
/* xml namespace */
|
||||||
|
if (xmlStrEqual(ns->prefix, BAD_CAST "xml"))
|
||||||
|
return(1);
|
||||||
|
|
||||||
while ((node != NULL) &&
|
while ((node != NULL) &&
|
||||||
((node->type == XML_ELEMENT_NODE) ||
|
((node->type == XML_ELEMENT_NODE) ||
|
||||||
(node->type == XML_ATTRIBUTE_NODE) ||
|
(node->type == XML_ATTRIBUTE_NODE) ||
|
||||||
@@ -119,14 +123,7 @@ xmlNsCheckScope(xmlNodePtr node, xmlNsPtr ns)
|
|||||||
}
|
}
|
||||||
node = node->parent;
|
node = node->parent;
|
||||||
}
|
}
|
||||||
/* the xml namespace may be declared on the document node */
|
|
||||||
if ((node != NULL) &&
|
|
||||||
((node->type == XML_DOCUMENT_NODE) ||
|
|
||||||
(node->type == XML_HTML_DOCUMENT_NODE))) {
|
|
||||||
xmlNsPtr oldNs = ((xmlDocPtr) node)->oldNs;
|
|
||||||
if (oldNs == ns)
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
return(-3);
|
return(-3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -9,8 +9,9 @@
|
|||||||
XML_HIDDEN extern int
|
XML_HIDDEN extern int
|
||||||
__xmlRegisterCallbacks;
|
__xmlRegisterCallbacks;
|
||||||
|
|
||||||
XML_HIDDEN xmlNsPtr
|
XML_HIDDEN extern xmlNsPtr
|
||||||
xmlTreeEnsureXMLDecl(xmlDocPtr doc);
|
xmlXmlNamespace;
|
||||||
|
|
||||||
XML_HIDDEN xmlNodePtr
|
XML_HIDDEN xmlNodePtr
|
||||||
xmlStaticCopyNode(xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent,
|
xmlStaticCopyNode(xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent,
|
||||||
int extended);
|
int extended);
|
||||||
|
7
parser.c
7
parser.c
@@ -2980,13 +2980,6 @@ xmlSplitQName(xmlParserCtxtPtr ctxt, const xmlChar *name, xmlChar **prefixOut) {
|
|||||||
|
|
||||||
if (cur == NULL) return(NULL);
|
if (cur == NULL) return(NULL);
|
||||||
|
|
||||||
#ifndef XML_XML_NAMESPACE
|
|
||||||
/* xml: prefix is not really a namespace */
|
|
||||||
if ((cur[0] == 'x') && (cur[1] == 'm') &&
|
|
||||||
(cur[2] == 'l') && (cur[3] == ':'))
|
|
||||||
return(xmlStrdup(name));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* nasty but well=formed */
|
/* nasty but well=formed */
|
||||||
if (cur[0] == ':')
|
if (cur[0] == ':')
|
||||||
return(xmlStrdup(name));
|
return(xmlStrdup(name));
|
||||||
|
@@ -68,14 +68,14 @@ testBalancedChunk(void) {
|
|||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
ret = xmlParseBalancedChunkMemory(NULL, NULL, NULL, 0,
|
ret = xmlParseBalancedChunkMemory(NULL, NULL, NULL, 0,
|
||||||
BAD_CAST "start <node xml:lang='en'>abc</node> end", &list);
|
BAD_CAST "start <xml:node>abc</xml:node> end", &list);
|
||||||
|
|
||||||
if ((ret != XML_ERR_OK) ||
|
if ((ret != XML_ERR_OK) ||
|
||||||
(list == NULL) ||
|
(list == NULL) ||
|
||||||
((elem = list->next) == NULL) ||
|
((elem = list->next) == NULL) ||
|
||||||
(elem->type != XML_ELEMENT_NODE) ||
|
(elem->type != XML_ELEMENT_NODE) ||
|
||||||
(elem->nsDef == NULL) ||
|
(elem->ns == NULL) ||
|
||||||
(!xmlStrEqual(elem->nsDef->href, XML_XML_NAMESPACE))) {
|
(!xmlStrEqual(elem->ns->href, XML_XML_NAMESPACE))) {
|
||||||
fprintf(stderr, "xmlParseBalancedChunkMemory failed\n");
|
fprintf(stderr, "xmlParseBalancedChunkMemory failed\n");
|
||||||
err = 1;
|
err = 1;
|
||||||
}
|
}
|
||||||
|
252
tree.c
252
tree.c
@@ -75,6 +75,16 @@ const xmlChar xmlStringComment[] = { 'c', 'o', 'm', 'm', 'e', 'n', 't', 0 };
|
|||||||
|
|
||||||
static int xmlCompressMode = 0;
|
static int xmlCompressMode = 0;
|
||||||
|
|
||||||
|
static const xmlNs xmlXmlNamespaceStruct = {
|
||||||
|
NULL,
|
||||||
|
XML_NAMESPACE_DECL,
|
||||||
|
XML_XML_NAMESPACE,
|
||||||
|
BAD_CAST "xml",
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
xmlNsPtr xmlXmlNamespace = (xmlNsPtr) &xmlXmlNamespaceStruct;
|
||||||
|
|
||||||
#define UPDATE_LAST_CHILD_AND_PARENT(n) if ((n) != NULL) { \
|
#define UPDATE_LAST_CHILD_AND_PARENT(n) if ((n) != NULL) { \
|
||||||
xmlNodePtr ulccur = (n)->children; \
|
xmlNodePtr ulccur = (n)->children; \
|
||||||
if (ulccur == NULL) { \
|
if (ulccur == NULL) { \
|
||||||
@@ -218,13 +228,6 @@ xmlSplitQName2(const xmlChar *name, xmlChar **prefix) {
|
|||||||
*prefix = NULL;
|
*prefix = NULL;
|
||||||
if (name == NULL) return(NULL);
|
if (name == NULL) return(NULL);
|
||||||
|
|
||||||
#ifndef XML_XML_NAMESPACE
|
|
||||||
/* xml: prefix is not really a namespace */
|
|
||||||
if ((name[0] == 'x') && (name[1] == 'm') &&
|
|
||||||
(name[2] == 'l') && (name[3] == ':'))
|
|
||||||
return(NULL);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* nasty but valid */
|
/* nasty but valid */
|
||||||
if (name[0] == ':')
|
if (name[0] == ':')
|
||||||
return(NULL);
|
return(NULL);
|
||||||
@@ -3937,14 +3940,14 @@ xmlCopyPropInternal(xmlDocPtr doc, xmlNodePtr target, xmlAttrPtr cur) {
|
|||||||
if ((cur->ns != NULL) && (target != NULL)) {
|
if ((cur->ns != NULL) && (target != NULL)) {
|
||||||
xmlNsPtr ns;
|
xmlNsPtr ns;
|
||||||
|
|
||||||
ns = xmlSearchNs(target->doc, target, cur->ns->prefix);
|
ns = xmlSearchNs(NULL, target, cur->ns->prefix);
|
||||||
if (ns == NULL) {
|
if (ns == NULL) {
|
||||||
/*
|
/*
|
||||||
* Humm, we are copying an element whose namespace is defined
|
* Humm, we are copying an element whose namespace is defined
|
||||||
* out of the new tree scope. Search it in the original tree
|
* out of the new tree scope. Search it in the original tree
|
||||||
* and add it at the top of the new tree
|
* and add it at the top of the new tree
|
||||||
*/
|
*/
|
||||||
ns = xmlSearchNs(cur->doc, cur->parent, cur->ns->prefix);
|
ns = xmlSearchNs(NULL, cur->parent, cur->ns->prefix);
|
||||||
if (ns != NULL) {
|
if (ns != NULL) {
|
||||||
xmlNodePtr root = target;
|
xmlNodePtr root = target;
|
||||||
xmlNodePtr pred = NULL;
|
xmlNodePtr pred = NULL;
|
||||||
@@ -3975,7 +3978,7 @@ xmlCopyPropInternal(xmlDocPtr doc, xmlNodePtr target, xmlAttrPtr cur) {
|
|||||||
* we are in trouble: we need a new reconciled namespace.
|
* we are in trouble: we need a new reconciled namespace.
|
||||||
* This is expensive
|
* This is expensive
|
||||||
*/
|
*/
|
||||||
ret->ns = xmlNewReconciledNs(target->doc, target, cur->ns);
|
ret->ns = xmlNewReconciledNs(NULL, target, cur->ns);
|
||||||
if (ret->ns == NULL)
|
if (ret->ns == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@@ -4208,7 +4211,7 @@ xmlStaticCopyNode(xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent,
|
|||||||
if ((node->type == XML_ELEMENT_NODE) && (node->ns != NULL)) {
|
if ((node->type == XML_ELEMENT_NODE) && (node->ns != NULL)) {
|
||||||
xmlNsPtr ns;
|
xmlNsPtr ns;
|
||||||
|
|
||||||
ns = xmlSearchNs(doc, ret, node->ns->prefix);
|
ns = xmlSearchNs(NULL, ret, node->ns->prefix);
|
||||||
if (ns == NULL) {
|
if (ns == NULL) {
|
||||||
/*
|
/*
|
||||||
* Humm, we are copying an element whose namespace is defined
|
* Humm, we are copying an element whose namespace is defined
|
||||||
@@ -4218,14 +4221,14 @@ xmlStaticCopyNode(xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent,
|
|||||||
* TODO: Searching the original tree seems unnecessary. We
|
* TODO: Searching the original tree seems unnecessary. We
|
||||||
* already have a namespace URI.
|
* already have a namespace URI.
|
||||||
*/
|
*/
|
||||||
ns = xmlSearchNs(node->doc, node, node->ns->prefix);
|
ns = xmlSearchNs(NULL, node, node->ns->prefix);
|
||||||
if (ns != NULL) {
|
if (ns != NULL) {
|
||||||
xmlNodePtr root = ret;
|
xmlNodePtr root = ret;
|
||||||
|
|
||||||
while (root->parent != NULL) root = root->parent;
|
while (root->parent != NULL) root = root->parent;
|
||||||
ret->ns = xmlNewNs(root, ns->href, ns->prefix);
|
ret->ns = xmlNewNs(root, ns->href, ns->prefix);
|
||||||
} else {
|
} else {
|
||||||
ret->ns = xmlNewReconciledNs(doc, ret, node->ns);
|
ret->ns = xmlNewReconciledNs(NULL, ret, node->ns);
|
||||||
}
|
}
|
||||||
if (ret->ns == NULL)
|
if (ret->ns == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
@@ -5070,9 +5073,7 @@ xmlNodeSetLang(xmlNodePtr cur, const xmlChar *lang) {
|
|||||||
case XML_ATTRIBUTE_NODE:
|
case XML_ATTRIBUTE_NODE:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ns = xmlSearchNsByHref(cur->doc, cur, XML_XML_NAMESPACE);
|
ns = xmlXmlNamespace;
|
||||||
if (ns == NULL)
|
|
||||||
return;
|
|
||||||
xmlSetNsProp(cur, ns, BAD_CAST "lang", lang);
|
xmlSetNsProp(cur, ns, BAD_CAST "lang", lang);
|
||||||
}
|
}
|
||||||
#endif /* LIBXML_TREE_ENABLED */
|
#endif /* LIBXML_TREE_ENABLED */
|
||||||
@@ -5141,9 +5142,7 @@ xmlNodeSetSpacePreserve(xmlNodePtr cur, int val) {
|
|||||||
case XML_ATTRIBUTE_NODE:
|
case XML_ATTRIBUTE_NODE:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ns = xmlSearchNsByHref(cur->doc, cur, XML_XML_NAMESPACE);
|
ns = xmlXmlNamespace;
|
||||||
if (ns == NULL)
|
|
||||||
return;
|
|
||||||
switch (val) {
|
switch (val) {
|
||||||
case 0:
|
case 0:
|
||||||
xmlSetNsProp(cur, ns, BAD_CAST "space", BAD_CAST "default");
|
xmlSetNsProp(cur, ns, BAD_CAST "space", BAD_CAST "default");
|
||||||
@@ -5294,9 +5293,7 @@ xmlNodeSetBase(xmlNodePtr cur, const xmlChar* uri) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ns = xmlSearchNsByHref(cur->doc, cur, XML_XML_NAMESPACE);
|
ns = xmlXmlNamespace;
|
||||||
if (ns == NULL)
|
|
||||||
return(-1);
|
|
||||||
fixed = xmlPathToURI(uri);
|
fixed = xmlPathToURI(uri);
|
||||||
if (fixed == NULL)
|
if (fixed == NULL)
|
||||||
return(-1);
|
return(-1);
|
||||||
@@ -6056,43 +6053,6 @@ xmlGetNsList(const xmlDoc *doc, const xmlNode *node)
|
|||||||
}
|
}
|
||||||
#endif /* LIBXML_TREE_ENABLED */
|
#endif /* LIBXML_TREE_ENABLED */
|
||||||
|
|
||||||
/*
|
|
||||||
* xmlTreeEnsureXMLDecl:
|
|
||||||
* @doc: the doc
|
|
||||||
*
|
|
||||||
* Ensures that there is an XML namespace declaration on the doc.
|
|
||||||
*
|
|
||||||
* Returns the XML ns-struct or NULL if a memory allocation failed.
|
|
||||||
*/
|
|
||||||
xmlNsPtr
|
|
||||||
xmlTreeEnsureXMLDecl(xmlDocPtr doc)
|
|
||||||
{
|
|
||||||
if (doc == NULL)
|
|
||||||
return (NULL);
|
|
||||||
if (doc->oldNs != NULL)
|
|
||||||
return (doc->oldNs);
|
|
||||||
{
|
|
||||||
xmlNsPtr ns;
|
|
||||||
ns = (xmlNsPtr) xmlMalloc(sizeof(xmlNs));
|
|
||||||
if (ns == NULL)
|
|
||||||
return(NULL);
|
|
||||||
memset(ns, 0, sizeof(xmlNs));
|
|
||||||
ns->type = XML_LOCAL_NAMESPACE;
|
|
||||||
ns->href = xmlStrdup(XML_XML_NAMESPACE);
|
|
||||||
if (ns->href == NULL) {
|
|
||||||
xmlFreeNs(ns);
|
|
||||||
return(NULL);
|
|
||||||
}
|
|
||||||
ns->prefix = xmlStrdup((const xmlChar *)"xml");
|
|
||||||
if (ns->prefix == NULL) {
|
|
||||||
xmlFreeNs(ns);
|
|
||||||
return(NULL);
|
|
||||||
}
|
|
||||||
doc->oldNs = ns;
|
|
||||||
return (ns);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* xmlSearchNs:
|
* xmlSearchNs:
|
||||||
* @doc: the document
|
* @doc: the document
|
||||||
@@ -6107,50 +6067,20 @@ xmlTreeEnsureXMLDecl(xmlDocPtr doc)
|
|||||||
* the namespace within those you will be in troubles !!! A warning
|
* the namespace within those you will be in troubles !!! A warning
|
||||||
* is generated to cover this case.
|
* is generated to cover this case.
|
||||||
*
|
*
|
||||||
* Returns the namespace pointer or NULL if no namespace was found or
|
* Returns the namespace pointer or NULL if no namespace was found.
|
||||||
* a memory allocation failed. Allocations can only fail if the "xml"
|
|
||||||
* namespace is queried and xmlTreeEnsureXMLDecl wasn't called
|
|
||||||
* successfully or doc is NULL.
|
|
||||||
*/
|
*/
|
||||||
xmlNsPtr
|
xmlNsPtr
|
||||||
xmlSearchNs(xmlDocPtr doc, xmlNodePtr node, const xmlChar *nameSpace) {
|
xmlSearchNs(xmlDocPtr doc ATTRIBUTE_UNUSED, xmlNodePtr node,
|
||||||
|
const xmlChar *nameSpace) {
|
||||||
xmlNsPtr cur;
|
xmlNsPtr cur;
|
||||||
const xmlNode *orig = node;
|
const xmlNode *orig = node;
|
||||||
|
|
||||||
if ((node == NULL) || (node->type == XML_NAMESPACE_DECL)) return(NULL);
|
if ((node == NULL) || (node->type == XML_NAMESPACE_DECL))
|
||||||
if ((nameSpace != NULL) &&
|
return(NULL);
|
||||||
(xmlStrEqual(nameSpace, (const xmlChar *)"xml"))) {
|
|
||||||
if ((doc == NULL) && (node->type == XML_ELEMENT_NODE)) {
|
if (xmlStrEqual(nameSpace, BAD_CAST "xml"))
|
||||||
/*
|
return(xmlXmlNamespace);
|
||||||
* The XML-1.0 namespace is normally held on the root
|
|
||||||
* element. In this case exceptionally create it on the
|
|
||||||
* node element.
|
|
||||||
*/
|
|
||||||
cur = (xmlNsPtr) xmlMalloc(sizeof(xmlNs));
|
|
||||||
if (cur == NULL)
|
|
||||||
return(NULL);
|
|
||||||
memset(cur, 0, sizeof(xmlNs));
|
|
||||||
cur->type = XML_LOCAL_NAMESPACE;
|
|
||||||
cur->href = xmlStrdup(XML_XML_NAMESPACE);
|
|
||||||
cur->prefix = xmlStrdup((const xmlChar *)"xml");
|
|
||||||
cur->next = node->nsDef;
|
|
||||||
node->nsDef = cur;
|
|
||||||
return(cur);
|
|
||||||
}
|
|
||||||
if (doc == NULL) {
|
|
||||||
doc = node->doc;
|
|
||||||
if (doc == NULL)
|
|
||||||
return(NULL);
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* Return the XML namespace declaration held by the doc.
|
|
||||||
*/
|
|
||||||
if (doc->oldNs == NULL)
|
|
||||||
return(xmlTreeEnsureXMLDecl(doc));
|
|
||||||
else
|
|
||||||
return(doc->oldNs);
|
|
||||||
}
|
|
||||||
while (node != NULL) {
|
while (node != NULL) {
|
||||||
if ((node->type == XML_ENTITY_REF_NODE) ||
|
if ((node->type == XML_ENTITY_REF_NODE) ||
|
||||||
(node->type == XML_ENTITY_NODE) ||
|
(node->type == XML_ENTITY_NODE) ||
|
||||||
@@ -6238,54 +6168,21 @@ xmlNsInScope(xmlDocPtr doc ATTRIBUTE_UNUSED, xmlNodePtr node,
|
|||||||
* Search a Ns aliasing a given URI. Recurse on the parents until it finds
|
* Search a Ns aliasing a given URI. Recurse on the parents until it finds
|
||||||
* the defined namespace or return NULL otherwise.
|
* the defined namespace or return NULL otherwise.
|
||||||
*
|
*
|
||||||
* Returns the namespace pointer or NULL if no namespace was found or
|
* Returns the namespace pointer or NULL if no namespace was found.
|
||||||
* a memory allocation failed. Allocations can only fail if the "xml"
|
|
||||||
* namespace is queried and xmlTreeEnsureXMLDecl wasn't called
|
|
||||||
* successfully or doc is NULL.
|
|
||||||
*/
|
*/
|
||||||
xmlNsPtr
|
xmlNsPtr
|
||||||
xmlSearchNsByHref(xmlDocPtr doc, xmlNodePtr node, const xmlChar * href)
|
xmlSearchNsByHref(xmlDocPtr doc ATTRIBUTE_UNUSED, xmlNodePtr node,
|
||||||
{
|
const xmlChar * href) {
|
||||||
xmlNsPtr cur;
|
xmlNsPtr cur;
|
||||||
xmlNodePtr orig = node;
|
xmlNodePtr orig = node;
|
||||||
int is_attr;
|
int is_attr;
|
||||||
|
|
||||||
if ((node == NULL) || (node->type == XML_NAMESPACE_DECL) || (href == NULL))
|
if ((node == NULL) || (node->type == XML_NAMESPACE_DECL) || (href == NULL))
|
||||||
return (NULL);
|
return (NULL);
|
||||||
if (xmlStrEqual(href, XML_XML_NAMESPACE)) {
|
|
||||||
/*
|
if (xmlStrEqual(href, XML_XML_NAMESPACE))
|
||||||
* Only the document can hold the XML spec namespace.
|
return(xmlXmlNamespace);
|
||||||
*/
|
|
||||||
if ((doc == NULL) && (node->type == XML_ELEMENT_NODE)) {
|
|
||||||
/*
|
|
||||||
* The XML-1.0 namespace is normally held on the root
|
|
||||||
* element. In this case exceptionally create it on the
|
|
||||||
* node element.
|
|
||||||
*/
|
|
||||||
cur = (xmlNsPtr) xmlMalloc(sizeof(xmlNs));
|
|
||||||
if (cur == NULL)
|
|
||||||
return (NULL);
|
|
||||||
memset(cur, 0, sizeof(xmlNs));
|
|
||||||
cur->type = XML_LOCAL_NAMESPACE;
|
|
||||||
cur->href = xmlStrdup(XML_XML_NAMESPACE);
|
|
||||||
cur->prefix = xmlStrdup((const xmlChar *) "xml");
|
|
||||||
cur->next = node->nsDef;
|
|
||||||
node->nsDef = cur;
|
|
||||||
return (cur);
|
|
||||||
}
|
|
||||||
if (doc == NULL) {
|
|
||||||
doc = node->doc;
|
|
||||||
if (doc == NULL)
|
|
||||||
return(NULL);
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* Return the XML namespace declaration held by the doc.
|
|
||||||
*/
|
|
||||||
if (doc->oldNs == NULL)
|
|
||||||
return(xmlTreeEnsureXMLDecl(doc));
|
|
||||||
else
|
|
||||||
return(doc->oldNs);
|
|
||||||
}
|
|
||||||
is_attr = (node->type == XML_ATTRIBUTE_NODE);
|
is_attr = (node->type == XML_ATTRIBUTE_NODE);
|
||||||
while (node != NULL) {
|
while (node != NULL) {
|
||||||
if ((node->type == XML_ENTITY_REF_NODE) ||
|
if ((node->type == XML_ENTITY_REF_NODE) ||
|
||||||
@@ -6298,7 +6195,7 @@ xmlSearchNsByHref(xmlDocPtr doc, xmlNodePtr node, const xmlChar * href)
|
|||||||
if ((cur->href != NULL) && (href != NULL) &&
|
if ((cur->href != NULL) && (href != NULL) &&
|
||||||
(xmlStrEqual(cur->href, href))) {
|
(xmlStrEqual(cur->href, href))) {
|
||||||
if (((!is_attr) || (cur->prefix != NULL)) &&
|
if (((!is_attr) || (cur->prefix != NULL)) &&
|
||||||
(xmlNsInScope(doc, orig, node, cur->prefix) == 1))
|
(xmlNsInScope(NULL, orig, node, cur->prefix) == 1))
|
||||||
return (cur);
|
return (cur);
|
||||||
}
|
}
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
@@ -6309,7 +6206,7 @@ xmlSearchNsByHref(xmlDocPtr doc, xmlNodePtr node, const xmlChar * href)
|
|||||||
if ((cur->href != NULL) && (href != NULL) &&
|
if ((cur->href != NULL) && (href != NULL) &&
|
||||||
(xmlStrEqual(cur->href, href))) {
|
(xmlStrEqual(cur->href, href))) {
|
||||||
if (((!is_attr) || (cur->prefix != NULL)) &&
|
if (((!is_attr) || (cur->prefix != NULL)) &&
|
||||||
(xmlNsInScope(doc, orig, node, cur->prefix) == 1))
|
(xmlNsInScope(NULL, orig, node, cur->prefix) == 1))
|
||||||
return (cur);
|
return (cur);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6334,7 +6231,8 @@ xmlSearchNsByHref(xmlDocPtr doc, xmlNodePtr node, const xmlChar * href)
|
|||||||
* Returns the (new) namespace definition or NULL in case of error
|
* Returns the (new) namespace definition or NULL in case of error
|
||||||
*/
|
*/
|
||||||
static xmlNsPtr
|
static xmlNsPtr
|
||||||
xmlNewReconciledNs(xmlDocPtr doc, xmlNodePtr tree, xmlNsPtr ns) {
|
xmlNewReconciledNs(xmlDocPtr doc ATTRIBUTE_UNUSED, xmlNodePtr tree,
|
||||||
|
xmlNsPtr ns) {
|
||||||
xmlNsPtr def;
|
xmlNsPtr def;
|
||||||
xmlChar prefix[50];
|
xmlChar prefix[50];
|
||||||
int counter = 1;
|
int counter = 1;
|
||||||
@@ -6348,7 +6246,7 @@ xmlNewReconciledNs(xmlDocPtr doc, xmlNodePtr tree, xmlNsPtr ns) {
|
|||||||
/*
|
/*
|
||||||
* Search an existing namespace definition inherited.
|
* Search an existing namespace definition inherited.
|
||||||
*/
|
*/
|
||||||
def = xmlSearchNsByHref(doc, tree, ns->href);
|
def = xmlSearchNsByHref(NULL, tree, ns->href);
|
||||||
if (def != NULL)
|
if (def != NULL)
|
||||||
return(def);
|
return(def);
|
||||||
|
|
||||||
@@ -6361,7 +6259,7 @@ xmlNewReconciledNs(xmlDocPtr doc, xmlNodePtr tree, xmlNsPtr ns) {
|
|||||||
else
|
else
|
||||||
snprintf((char *) prefix, sizeof(prefix), "%.20s", (char *)ns->prefix);
|
snprintf((char *) prefix, sizeof(prefix), "%.20s", (char *)ns->prefix);
|
||||||
|
|
||||||
def = xmlSearchNs(doc, tree, prefix);
|
def = xmlSearchNs(NULL, tree, prefix);
|
||||||
while (def != NULL) {
|
while (def != NULL) {
|
||||||
if (counter > 1000) return(NULL);
|
if (counter > 1000) return(NULL);
|
||||||
if (ns->prefix == NULL)
|
if (ns->prefix == NULL)
|
||||||
@@ -6369,7 +6267,7 @@ xmlNewReconciledNs(xmlDocPtr doc, xmlNodePtr tree, xmlNsPtr ns) {
|
|||||||
else
|
else
|
||||||
snprintf((char *) prefix, sizeof(prefix), "%.20s%d",
|
snprintf((char *) prefix, sizeof(prefix), "%.20s%d",
|
||||||
(char *)ns->prefix, counter++);
|
(char *)ns->prefix, counter++);
|
||||||
def = xmlSearchNs(doc, tree, prefix);
|
def = xmlSearchNs(NULL, tree, prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -6402,7 +6300,7 @@ typedef struct {
|
|||||||
* Returns 0 on success or -1 in case of error.
|
* Returns 0 on success or -1 in case of error.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
xmlReconciliateNs(xmlDocPtr doc, xmlNodePtr tree) {
|
xmlReconciliateNs(xmlDocPtr doc ATTRIBUTE_UNUSED, xmlNodePtr tree) {
|
||||||
xmlNsCache *cache = NULL;
|
xmlNsCache *cache = NULL;
|
||||||
int sizeCache = 0;
|
int sizeCache = 0;
|
||||||
int nbCache = 0;
|
int nbCache = 0;
|
||||||
@@ -6412,8 +6310,9 @@ xmlReconciliateNs(xmlDocPtr doc, xmlNodePtr tree) {
|
|||||||
xmlAttrPtr attr;
|
xmlAttrPtr attr;
|
||||||
int ret = 0, i;
|
int ret = 0, i;
|
||||||
|
|
||||||
if ((node == NULL) || (node->type != XML_ELEMENT_NODE)) return(-1);
|
if ((node == NULL) || (node->type != XML_ELEMENT_NODE))
|
||||||
if (node->doc != doc) return(-1);
|
return(-1);
|
||||||
|
|
||||||
while (node != NULL) {
|
while (node != NULL) {
|
||||||
/*
|
/*
|
||||||
* Reconciliate the node namespace
|
* Reconciliate the node namespace
|
||||||
@@ -6429,7 +6328,7 @@ xmlReconciliateNs(xmlDocPtr doc, xmlNodePtr tree) {
|
|||||||
/*
|
/*
|
||||||
* OK we need to recreate a new namespace definition
|
* OK we need to recreate a new namespace definition
|
||||||
*/
|
*/
|
||||||
n = xmlNewReconciledNs(doc, tree, node->ns);
|
n = xmlNewReconciledNs(NULL, tree, node->ns);
|
||||||
if (n == NULL) {
|
if (n == NULL) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
} else {
|
} else {
|
||||||
@@ -6473,7 +6372,7 @@ xmlReconciliateNs(xmlDocPtr doc, xmlNodePtr tree) {
|
|||||||
/*
|
/*
|
||||||
* OK we need to recreate a new namespace definition
|
* OK we need to recreate a new namespace definition
|
||||||
*/
|
*/
|
||||||
n = xmlNewReconciledNs(doc, tree, attr->ns);
|
n = xmlNewReconciledNs(NULL, tree, attr->ns);
|
||||||
if (n == NULL) {
|
if (n == NULL) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
} else {
|
} else {
|
||||||
@@ -6964,7 +6863,7 @@ xmlSetProp(xmlNodePtr node, const xmlChar *name, const xmlChar *value) {
|
|||||||
if (nqname != NULL) {
|
if (nqname != NULL) {
|
||||||
xmlNsPtr ns;
|
xmlNsPtr ns;
|
||||||
xmlChar *prefix = xmlStrndup(name, len);
|
xmlChar *prefix = xmlStrndup(name, len);
|
||||||
ns = xmlSearchNs(node->doc, node, prefix);
|
ns = xmlSearchNs(NULL, node, prefix);
|
||||||
if (prefix != NULL)
|
if (prefix != NULL)
|
||||||
xmlFree(prefix);
|
xmlFree(prefix);
|
||||||
if (ns != NULL)
|
if (ns != NULL)
|
||||||
@@ -7989,28 +7888,29 @@ xmlDOMWrapStoreNs(xmlDocPtr doc,
|
|||||||
|
|
||||||
if (doc == NULL)
|
if (doc == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
ns = xmlTreeEnsureXMLDecl(doc);
|
|
||||||
if (ns == NULL)
|
/* Reuse. */
|
||||||
return (NULL);
|
ns = doc->oldNs;
|
||||||
if (ns->next != NULL) {
|
while (ns != NULL) {
|
||||||
/* Reuse. */
|
if (((ns->prefix == prefix) ||
|
||||||
ns = ns->next;
|
xmlStrEqual(ns->prefix, prefix)) &&
|
||||||
while (ns != NULL) {
|
xmlStrEqual(ns->href, nsName)) {
|
||||||
if (((ns->prefix == prefix) ||
|
return(ns);
|
||||||
xmlStrEqual(ns->prefix, prefix)) &&
|
}
|
||||||
xmlStrEqual(ns->href, nsName)) {
|
if (ns->next == NULL)
|
||||||
return (ns);
|
break;
|
||||||
}
|
ns = ns->next;
|
||||||
if (ns->next == NULL)
|
|
||||||
break;
|
|
||||||
ns = ns->next;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create. */
|
/* Create. */
|
||||||
if (ns != NULL) {
|
if (ns == NULL) {
|
||||||
|
doc->oldNs = xmlNewNs(NULL, nsName, prefix);
|
||||||
|
return(doc->oldNs);
|
||||||
|
} else {
|
||||||
ns->next = xmlNewNs(NULL, nsName, prefix);
|
ns->next = xmlNewNs(NULL, nsName, prefix);
|
||||||
return (ns->next);
|
return(ns->next);
|
||||||
}
|
}
|
||||||
|
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -8372,9 +8272,7 @@ xmlSearchNsByNamespaceStrict(xmlDocPtr doc, xmlNodePtr node,
|
|||||||
|
|
||||||
*retNs = NULL;
|
*retNs = NULL;
|
||||||
if (xmlStrEqual(nsName, XML_XML_NAMESPACE)) {
|
if (xmlStrEqual(nsName, XML_XML_NAMESPACE)) {
|
||||||
*retNs = xmlTreeEnsureXMLDecl(doc);
|
*retNs = xmlXmlNamespace;
|
||||||
if (*retNs == NULL)
|
|
||||||
return (-1);
|
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
cur = node;
|
cur = node;
|
||||||
@@ -8418,7 +8316,7 @@ xmlSearchNsByNamespaceStrict(xmlDocPtr doc, xmlNodePtr node,
|
|||||||
if (out) {
|
if (out) {
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = xmlNsInScope(doc, node, prev, ns->prefix);
|
ret = xmlNsInScope(NULL, node, prev, ns->prefix);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return (-1);
|
return (-1);
|
||||||
/*
|
/*
|
||||||
@@ -8474,9 +8372,7 @@ xmlSearchNsByPrefixStrict(xmlDocPtr doc, xmlNodePtr node,
|
|||||||
*retNs = NULL;
|
*retNs = NULL;
|
||||||
if (IS_STR_XML(prefix)) {
|
if (IS_STR_XML(prefix)) {
|
||||||
if (retNs) {
|
if (retNs) {
|
||||||
*retNs = xmlTreeEnsureXMLDecl(doc);
|
*retNs = xmlXmlNamespace;
|
||||||
if (*retNs == NULL)
|
|
||||||
return (-1);
|
|
||||||
}
|
}
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
@@ -8628,9 +8524,7 @@ xmlDOMWrapNSNormAcquireNormalizedNs(xmlDocPtr doc,
|
|||||||
/*
|
/*
|
||||||
* Insert XML namespace mapping.
|
* Insert XML namespace mapping.
|
||||||
*/
|
*/
|
||||||
*retNs = xmlTreeEnsureXMLDecl(doc);
|
*retNs = xmlXmlNamespace;
|
||||||
if (*retNs == NULL)
|
|
||||||
return (-1);
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@@ -9921,7 +9815,7 @@ xmlDOMWrapAdoptAttr(xmlDOMWrapCtxtPtr ctxt,
|
|||||||
}
|
}
|
||||||
/* XML Namespace. */
|
/* XML Namespace. */
|
||||||
if (IS_STR_XML(attr->ns->prefix)) {
|
if (IS_STR_XML(attr->ns->prefix)) {
|
||||||
ns = xmlTreeEnsureXMLDecl(destDoc);
|
ns = xmlXmlNamespace;
|
||||||
} else if (destParent == NULL) {
|
} else if (destParent == NULL) {
|
||||||
/*
|
/*
|
||||||
* Store in @destDoc->oldNs.
|
* Store in @destDoc->oldNs.
|
||||||
|
14
xpath.c
14
xpath.c
@@ -49,6 +49,7 @@
|
|||||||
|
|
||||||
#include "private/buf.h"
|
#include "private/buf.h"
|
||||||
#include "private/error.h"
|
#include "private/error.h"
|
||||||
|
#include "private/tree.h"
|
||||||
#include "private/xpath.h"
|
#include "private/xpath.h"
|
||||||
|
|
||||||
/* Disabled for now */
|
/* Disabled for now */
|
||||||
@@ -224,15 +225,6 @@ xmlXPathIsInf(double val) {
|
|||||||
* the test should just be name[0] = ' '
|
* the test should just be name[0] = ' '
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static xmlNs xmlXPathXMLNamespaceStruct = {
|
|
||||||
NULL,
|
|
||||||
XML_NAMESPACE_DECL,
|
|
||||||
XML_XML_NAMESPACE,
|
|
||||||
BAD_CAST "xml",
|
|
||||||
NULL,
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
static xmlNsPtr xmlXPathXMLNamespace = &xmlXPathXMLNamespaceStruct;
|
|
||||||
#ifndef LIBXML_THREAD_ENABLED
|
#ifndef LIBXML_THREAD_ENABLED
|
||||||
/*
|
/*
|
||||||
* Optimizer is disabled only when threaded apps are detected while
|
* Optimizer is disabled only when threaded apps are detected while
|
||||||
@@ -4260,10 +4252,8 @@ xmlXPathNsLookup(xmlXPathContextPtr ctxt, const xmlChar *prefix) {
|
|||||||
if (prefix == NULL)
|
if (prefix == NULL)
|
||||||
return(NULL);
|
return(NULL);
|
||||||
|
|
||||||
#ifdef XML_XML_NAMESPACE
|
|
||||||
if (xmlStrEqual(prefix, (const xmlChar *) "xml"))
|
if (xmlStrEqual(prefix, (const xmlChar *) "xml"))
|
||||||
return(XML_XML_NAMESPACE);
|
return(XML_XML_NAMESPACE);
|
||||||
#endif
|
|
||||||
|
|
||||||
if (ctxt->namespaces != NULL) {
|
if (ctxt->namespaces != NULL) {
|
||||||
int i;
|
int i;
|
||||||
@@ -7344,7 +7334,7 @@ xmlXPathNextNamespace(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
|
|||||||
ctxt->context->tmpNsNr++;
|
ctxt->context->tmpNsNr++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return((xmlNodePtr) xmlXPathXMLNamespace);
|
return((xmlNodePtr) xmlXmlNamespace);
|
||||||
}
|
}
|
||||||
if (ctxt->context->tmpNsNr > 0) {
|
if (ctxt->context->tmpNsNr > 0) {
|
||||||
return (xmlNodePtr)ctxt->context->tmpNsList[--ctxt->context->tmpNsNr];
|
return (xmlNodePtr)ctxt->context->tmpNsList[--ctxt->context->tmpNsNr];
|
||||||
|
Reference in New Issue
Block a user