[lxml-dev] XMLSchemaParseError if XML schema namespace uri is not "http://www.w3.org/2001/XMLSchema"

Kev Dwyer kevin.p.dwyer at gmail.com
Fri Apr 3 17:42:44 CEST 2009


Hello,


This is a re-post of my earlier posting, at Stefan's request, without the
corporate boilerplate
that I inadvertently sent last time.  Sorry about that.

Bug 354574 logged at Stefan's request.


I have encountered a problem with schema object creation with lxml; the
problem relates to namespace used for the root element of the schema.

<snip>
>>> import lxml.etree
>>> et = lxml.etree.ElementTree(file=open('c:\\temp\\MySchema', 'r'))
>>> et
<lxml.etree._ElementTree object at 0x011B8AF8>
>>> xsd = lxml.etree.XMLSchema(et)

Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    xsd = lxml.etree.XMLSchema(et)
  File "xmlschema.pxi", line 50, in lxml.etree.XMLSchema.__init__
(src/lxml/lxml.etree.c:120919)
XMLSchemaParseError: Document is not XML Schema
</snip>

Looking in subversion
(http://codespeak.net/svn/lxml/trunk/src/lxml/xmlschema.pxi), in the
XMLSchema class I see:

<snip>

            # work around for libxml2 bug if document is not XML schema at
all
            #if _LIBXML_VERSION_INT < 20624:
            c_node = root_node._c_node
            c_href = _getNs(c_node)
            if c_href is NULL or \
                   cstd.strcmp(c_href, 'http://www.w3.org/2001/XMLSchema')
!= 0:
                raise XMLSchemaParseError, u"Document is not XML Schema"
</snip>
The schemas that I am using use this root element:
<xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema">
If I change them to <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
they validate.
Can you explain why the earlier namespace definition is unacceptable?
Is there a workaround?
The schemas are not built by my application, so changing them might be
an issue.

Cheers,



Kevin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://codespeak.net/pipermail/lxml-dev/attachments/20090403/02eb6f38/attachment.htm 


More information about the lxml-dev mailing list