diff --git a/ChangeLog b/ChangeLog index e9c187ea..cfe766ed 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Mon Dec 30 11:53:44 CET 2002 Daniel Veillard + + * 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 * entities.c parser.c tree.c include/libxml/entities.h: Fixed diff --git a/SAX.c b/SAX.c index 74218f34..569671c7 100644 --- a/SAX.c +++ b/SAX.c @@ -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); diff --git a/python/tests/reader.py b/python/tests/reader.py index c615c700..75d6d8d0 100755 --- a/python/tests/reader.py +++ b/python/tests/reader.py @@ -264,6 +264,42 @@ if res != expect: print res sys.exit(1) +# +# a couple of tests for namespace nodes +# +f = StringIO.StringIO("""""") +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("""""") +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 diff --git a/xmlreader.c b/xmlreader.c index a32ec307..3bca6c8f 100644 --- a/xmlreader.c +++ b/xmlreader.c @@ -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);