1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-08-01 10:06:59 +03:00

- tree.[ch] parser.c xpath.c: fixed the problem of addressing

attributes within the XML-1.0 namespace
Daniel
This commit is contained in:
Daniel Veillard
2001-02-16 00:11:46 +00:00
parent 6e6a6cc6e7
commit e0e265138e
6 changed files with 74 additions and 2 deletions

View File

@ -1,3 +1,8 @@
Fri Feb 16 01:10:06 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
* tree.[ch] parser.c xpath.c: fixed the problem of addressing
attributes within the XML-1.0 namespace
Thu Feb 15 16:53:20 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr> Thu Feb 15 16:53:20 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
* xpathInternals.h: exported a few axis functions * xpathInternals.h: exported a few axis functions

View File

@ -20,6 +20,9 @@
extern "C" { extern "C" {
#endif #endif
#define XML_XML_NAMESPACE \
(const xmlChar *) "http://www.w3.org/XML/1998/namespace"
/* /*
* The different element types carried by an XML tree * The different element types carried by an XML tree
* *

View File

@ -1473,10 +1473,12 @@ xmlSplitQName(xmlParserCtxtPtr ctxt, const xmlChar *name, xmlChar **prefix) {
*prefix = NULL; *prefix = NULL;
#ifndef XML_XML_NAMESPACE
/* xml: prefix is not really a namespace */ /* xml: prefix is not really a namespace */
if ((cur[0] == 'x') && (cur[1] == 'm') && if ((cur[0] == 'x') && (cur[1] == 'm') &&
(cur[2] == 'l') && (cur[3] == ':')) (cur[2] == 'l') && (cur[3] == ':'))
return(xmlStrdup(name)); return(xmlStrdup(name));
#endif
/* nasty but valid */ /* nasty but valid */
if (cur[0] == ':') if (cur[0] == ':')

39
tree.c
View File

@ -3615,6 +3615,26 @@ xmlSearchNs(xmlDocPtr doc, xmlNodePtr node, const xmlChar *nameSpace) {
xmlNsPtr cur; xmlNsPtr cur;
if (node == NULL) return(NULL); if (node == NULL) return(NULL);
if ((nameSpace != NULL) &&
(xmlStrEqual(nameSpace, (const xmlChar *)"xml"))) {
if (doc->oldNs == NULL) {
/*
* Allocate a new Namespace and fill the fields.
*/
doc->oldNs = (xmlNsPtr) xmlMalloc(sizeof(xmlNs));
if (doc->oldNs == NULL) {
xmlGenericError(xmlGenericErrorContext,
"xmlSearchNsByHref : malloc failed\n");
return(NULL);
}
memset(doc->oldNs, 0, sizeof(xmlNs));
doc->oldNs->type = XML_LOCAL_NAMESPACE;
doc->oldNs->href = xmlStrdup(XML_XML_NAMESPACE);
doc->oldNs->prefix = xmlStrdup((const xmlChar *)"xml");
}
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) ||
@ -3654,6 +3674,25 @@ xmlSearchNsByHref(xmlDocPtr doc, xmlNodePtr node, const xmlChar *href) {
xmlNodePtr orig = node; xmlNodePtr orig = node;
if ((node == NULL) || (href == NULL)) return(NULL); if ((node == NULL) || (href == NULL)) return(NULL);
if (xmlStrEqual(href, XML_XML_NAMESPACE)) {
if (doc->oldNs == NULL) {
/*
* Allocate a new Namespace and fill the fields.
*/
doc->oldNs = (xmlNsPtr) xmlMalloc(sizeof(xmlNs));
if (doc->oldNs == NULL) {
xmlGenericError(xmlGenericErrorContext,
"xmlSearchNsByHref : malloc failed\n");
return(NULL);
}
memset(doc->oldNs, 0, sizeof(xmlNs));
doc->oldNs->type = XML_LOCAL_NAMESPACE;
doc->oldNs->href = xmlStrdup(XML_XML_NAMESPACE);
doc->oldNs->prefix = xmlStrdup((const xmlChar *)"xml");
}
return(doc->oldNs);
}
while (node != NULL) { while (node != NULL) {
cur = node->nsDef; cur = node->nsDef;
while (cur != NULL) { while (cur != NULL) {

3
tree.h
View File

@ -20,6 +20,9 @@
extern "C" { extern "C" {
#endif #endif
#define XML_XML_NAMESPACE \
(const xmlChar *) "http://www.w3.org/XML/1998/namespace"
/* /*
* The different element types carried by an XML tree * The different element types carried by an XML tree
* *

24
xpath.c
View File

@ -1344,6 +1344,12 @@ xmlXPathNsLookup(xmlXPathContextPtr ctxt, const xmlChar *prefix) {
return(NULL); return(NULL);
if (prefix == NULL) if (prefix == NULL)
return(NULL); return(NULL);
#ifdef XML_XML_NAMESPACE
if (xmlStrEqual(prefix, (const xmlChar *) "xml"))
return(XML_XML_NAMESPACE);
#endif
if (ctxt->nsHash == NULL) if (ctxt->nsHash == NULL)
return(NULL); return(NULL);
@ -3289,10 +3295,24 @@ xmlXPathNodeCollectAndTest(xmlXPathParserContextPtr ctxt, xmlXPathAxisVal axis,
case XML_ATTRIBUTE_NODE: { case XML_ATTRIBUTE_NODE: {
xmlAttrPtr attr = (xmlAttrPtr) cur; xmlAttrPtr attr = (xmlAttrPtr) cur;
if (xmlStrEqual(name, attr->name)) { if (xmlStrEqual(name, attr->name)) {
if (prefix == NULL) {
if ((attr->ns == NULL) ||
(attr->ns->prefix == NULL)) {
#ifdef DEBUG_STEP #ifdef DEBUG_STEP
n++; n++;
#endif #endif
addNode(ret, cur); addNode(ret, attr);
}
} else {
if ((attr->ns != NULL) &&
(xmlStrEqual(prefix,
attr->ns->href))) {
#ifdef DEBUG_STEP
n++;
#endif
addNode(ret, attr);
}
}
} }
break; break;
} }