sissaschool / xmlschema

XML Schema validator and data conversion library for Python
MIT License
414 stars 74 forks source link

Error on import XACML XSD #16

Closed welkson closed 7 years ago

welkson commented 7 years ago

Hi @brunato

XSD Schema: https://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd

Validation online (XSD Schema OK): http://www.utilities-online.info/xsdvalidation/#.Wa_0TBNSyF0

Using xmlschema lib (Python 2.7 / xmlschema 0.9.11):

import xmlschema
schema = xmlschema.XMLSchema('xacml-core-v3-schema-wd-17.xsd')

Error:

Traceback (most recent call last):
  File "test_xmltodict.py", line 64, in <module>
    schema = xmlschema.XMLSchema('xacml-core-v3-schema-wd-17.xsd')
  File "/Users/welkson/Envs/suap/lib/python2.7/site-packages/xmlschema/schema.py", line 195, in __init__
    self.maps.build()
  File "/Users/welkson/Envs/suap/lib/python2.7/site-packages/xmlschema/namespaces.py", line 343, in build
    self.lookup_type(qname)
  File "/Users/welkson/Envs/suap/lib/python2.7/site-packages/xmlschema/namespaces.py", line 199, in lookup
    global_map[qname] = factory_or_class(elem, schema, is_global=True)
  File "/Users/welkson/Envs/suap/lib/python2.7/site-packages/xmlschema/components/complex_types.py", line 48, in __init__
    super(XsdComplexType, self).__init__(elem, schema, name, is_global)
  File "/Users/welkson/Envs/suap/lib/python2.7/site-packages/xmlschema/components/component.py", line 45, in __init__
    self.elem = elem
  File "/Users/welkson/Envs/suap/lib/python2.7/site-packages/xmlschema/components/complex_types.py", line 68, in __setattr__
    super(XsdComplexType, self).__setattr__(name, value)
  File "/Users/welkson/Envs/suap/lib/python2.7/site-packages/xmlschema/components/component.py", line 61, in __setattr__
    self._parse()
  File "/Users/welkson/Envs/suap/lib/python2.7/site-packages/xmlschema/components/complex_types.py", line 128, in _parse
    base_type = self._parse_base_type(derivation_elem, complex_content=True)
  File "/Users/welkson/Envs/suap/lib/python2.7/site-packages/xmlschema/components/complex_types.py", line 161, in _parse_base_type
    base_type = self.maps.lookup_type(base_qname)
  File "/Users/welkson/Envs/suap/lib/python2.7/site-packages/xmlschema/namespaces.py", line 199, in lookup
    global_map[qname] = factory_or_class(elem, schema, is_global=True)
  File "/Users/welkson/Envs/suap/lib/python2.7/site-packages/xmlschema/components/complex_types.py", line 48, in __init__
    super(XsdComplexType, self).__init__(elem, schema, name, is_global)
  File "/Users/welkson/Envs/suap/lib/python2.7/site-packages/xmlschema/components/component.py", line 45, in __init__
    self.elem = elem
  File "/Users/welkson/Envs/suap/lib/python2.7/site-packages/xmlschema/components/complex_types.py", line 68, in __setattr__
    super(XsdComplexType, self).__setattr__(name, value)
  File "/Users/welkson/Envs/suap/lib/python2.7/site-packages/xmlschema/components/component.py", line 61, in __setattr__
    self._parse()
  File "/Users/welkson/Envs/suap/lib/python2.7/site-packages/xmlschema/components/complex_types.py", line 132, in _parse
    self._parse_complex_content_extension(derivation_elem, base_type)
  File "/Users/welkson/Envs/suap/lib/python2.7/site-packages/xmlschema/components/complex_types.py", line 289, in _parse_complex_content_extension
    "extension group is not empty." % base_type.mixed, elem)
  File "/Users/welkson/Envs/suap/lib/python2.7/site-packages/xmlschema/components/component.py", line 106, in _parse_error
    raise error
xmlschema.exceptions.XMLSchemaParseError: base has a different content type (mixed=False) and the extension group is not empty.

  <xs:extension xmlns:xs="http://www.w3.org/2001/XMLSchema" base="xacml:ExpressionType">
                <xs:sequence>
                    <xs:any maxOccurs="unbounded" minOccurs="0" namespace="##any" processContents="lax" />
                </xs:sequence>
                <xs:attribute name="DataType" type="xs:anyURI" use="required" />
                <xs:anyAttribute namespace="##any" processContents="lax" />
  </xs:extension>

Thanks in advance.

brunato commented 7 years ago

Found the bug (xmlschema/components/complex_types.py:line 95). The fix will be availabe in the next release.

brunato commented 7 years ago

Release 0.9.12 available on PyPI, the bug should be fixed.