warn on xmlns:prefix="foo" fixed a couple of problem for namespace

* SAX.c: warn on xmlns:prefix="foo"
* xmlreader.c python/tests/reader.py: fixed a couple of problem
  for namespace attributes handling.
Daniel
This commit is contained in:
Daniel Veillard 2002-12-30 10:55:29 +00:00
parent 2d84a89478
commit ecaba49a72
4 changed files with 64 additions and 6 deletions

View File

@ -1,3 +1,9 @@
Mon Dec 30 11:53:44 CET 2002 Daniel Veillard <daniel@veillard.com>
* SAX.c: warn on xmlns:prefix="foo"
* xmlreader.c python/tests/reader.py: fixed a couple of problem
for namespace attributes handling.
Mon Dec 30 00:59:07 CET 2002 Daniel Veillard <daniel@veillard.com>
* entities.c parser.c tree.c include/libxml/entities.h: Fixed

20
SAX.c
View File

@ -868,7 +868,7 @@ my_attribute(void *ctx, const xmlChar *fullname, const xmlChar *value,
if (uri->scheme == NULL) {
if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
ctxt->sax->warning(ctxt->userData,
"nmlns: URI %s is not absolute\n", value);
"xmlns: URI %s is not absolute\n", value);
}
xmlFreeURI(uri);
}
@ -901,6 +901,24 @@ my_attribute(void *ctx, const xmlChar *fullname, const xmlChar *value,
ctxt->sax->error(ctxt->userData,
"Empty namespace name for prefix %s\n", name);
}
if (value[0] != 0) {
xmlURIPtr uri;
uri = xmlParseURI((const char *)value);
if (uri == NULL) {
if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
ctxt->sax->warning(ctxt->userData,
"xmlns:%s: %s not a valid URI\n", name, value);
} else {
if (uri->scheme == NULL) {
if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
ctxt->sax->warning(ctxt->userData,
"xmlns:%s: URI %s is not absolute\n", name, value);
}
xmlFreeURI(uri);
}
}
/* a standard namespace definition */
nsret = xmlNewNs(ctxt->node, value, name);
xmlFree(ns);

View File

@ -264,6 +264,42 @@ if res != expect:
print res
sys.exit(1)
#
# a couple of tests for namespace nodes
#
f = StringIO.StringIO("""<a xmlns="http://example.com/foo">""")
input = libxml2.inputBuffer(f)
reader = input.newTextReader("test6")
ret = reader.Read()
if ret != 1:
print "test6: failed to Read()"
sys.exit(1)
ret = reader.MoveToFirstAttribute()
if ret != 1:
print "test6: failed to MoveToFirstAttribute()"
sys.exit(1)
if reader.NamespaceUri() != "http://www.w3.org/2000/xmlns/" or \
reader.LocalName() != "xmlns" or reader.Name() != "xmlns" or \
reader.Value() != "http://example.com/foo" or reader.NodeType() != 2:
print "test6: failed to read the namespace node"
sys.exit(1)
f = StringIO.StringIO("""<a xmlns:prefix="http://example.com/foo">""")
input = libxml2.inputBuffer(f)
reader = input.newTextReader("test7")
ret = reader.Read()
if ret != 1:
print "test7: failed to Read()"
sys.exit(1)
ret = reader.MoveToFirstAttribute()
if ret != 1:
print "test7: failed to MoveToFirstAttribute()"
sys.exit(1)
if reader.NamespaceUri() != "http://www.w3.org/2000/xmlns/" or \
reader.LocalName() != "prefix" or reader.Name() != "xmlns:prefix" or \
reader.Value() != "http://example.com/foo" or reader.NodeType() != 2:
print "test7: failed to read the namespace node"
sys.exit(1)
del f
del input

View File

@ -1369,6 +1369,7 @@ xmlTextReaderNodeType(xmlTextReaderPtr reader) {
(reader->state == XML_TEXTREADER_BACKTRACK))
return(15);
return(1);
case XML_NAMESPACE_DECL:
case XML_ATTRIBUTE_NODE:
return(2);
case XML_TEXT_NODE:
@ -1400,7 +1401,6 @@ xmlTextReaderNodeType(xmlTextReaderPtr reader) {
case XML_ELEMENT_DECL:
case XML_ATTRIBUTE_DECL:
case XML_ENTITY_DECL:
case XML_NAMESPACE_DECL:
case XML_XINCLUDE_START:
case XML_XINCLUDE_END:
return(0);
@ -1586,10 +1586,8 @@ xmlTextReaderNamespaceUri(xmlTextReaderPtr reader) {
node = reader->curnode;
else
node = reader->node;
if (node->type == XML_NAMESPACE_DECL) {
xmlNsPtr ns = (xmlNsPtr) node;
return(xmlStrdup(ns->href));
}
if (node->type == XML_NAMESPACE_DECL)
return(xmlStrdup(BAD_CAST "http://www.w3.org/2000/xmlns/"));
if ((node->type != XML_ELEMENT_NODE) &&
(node->type != XML_ATTRIBUTE_NODE))
return(NULL);