sissaschool / xmlschema

XML Schema validator and data conversion library for Python
MIT License
404 stars 76 forks source link

XMLSchemaParseError: wrong definition with self-reference #278

Closed winglian closed 2 years ago

winglian commented 2 years ago

I'm trying to load this XSD but I get the error below. I've been able to load this Schema with another library such as pyxb, so I'm not sure what I'm doing wrong here. My gut says it may be a bug where the library thinks that it's a self reference in the ERM namespace when in fact its a reference to another definition in the avs namespace. Any help is greatly appreciated. Thanks!

XMLSchemaParseError: wrong definition with self-reference:

Schema:

  <xs:complexType xmlns:xs="http://www.w3.org/2001/XMLSchema" name="AllTerritoryCode">
     <xs:annotation>
        <xs:documentation source="ddex:Definition">A Composite containing details of a
           TerritoryCode.</xs:documentation>
     </xs:annotation>
     <xs:simpleContent>
        <xs:extension base="avs:AllTerritoryCode">
           <xs:attribute name="IdentifierType" type="avs:TerritoryCodeTypeIncludingDeprecatedCodes">
              <xs:annotation>
                 <xs:documentation source="ddex:Definition">A standard used for the TerritoryCode.
                    This is represented in an XML schema as an XML Attribute. If this Attribute is
                    not provided, it is assumed that the code is a TerritoryCode in accordance with
                    ISO 3166-1 Alpha 2 standard (or Worldwide).</xs:documentation>
              </xs:annotation>
           </xs:attribute>
        </xs:extension>
     </xs:simpleContent>
  </xs:complexType>

Path: /xs:schema/xs:complexType[58]
brunato commented 2 years ago

Hi,

this is due to an error in XMLSchemaBase.simple_type_factory() when determine the name of the new type:

https://github.com/sissaschool/xmlschema/blob/dab51b775fb54c6626b9a4fb0a16f3e23ec07b44/xmlschema/validators/schemas.py#L812

this line has to be fixed using the target namespace of the schema associated to xsd_type:

            xsd_type.name = get_qname(schema.target_namespace, elem.attrib['name'])

usually the xsd_type.name is not checked so this error has no caused problems until now, but in these schemas the other namespace has a derivation from a simple type with the same local name that raises an error.

This fix will be included in the next release. Until that you can patch on your installed package or build the schema providing validation='lax'.

Thank you

brunato commented 2 years ago

Fixed by release v1.9.2.