[Python] how to use xsd with included and imported files with python

Discussão em 'Python' iniciado por Stack, Abril 7, 2025.

  1. Stack

    Stack Membro Participativo

    I have a base.xsd file which includes an enums.xsd. Both files are in the same directory.

    <xs:include id="enums" schemaLocation="enums.xsd"/>


    The enums.xsd imports:

    <xs:import
    namespace="http://www.wipo.int/standards/XMLSchema/Common/0"
    schemaLocation="ST96AnnexIIISchemas-V0-11/Common/0/Basic/ExtendedWIPOST3CodeType-V0-3.xsd"/>

    <xs:import
    namespace="http://www.wipo.int/standards/XMLSchema/Common/0"
    schemaLocation="ST96AnnexIIISchemas-V0-11/Common/0/Basic/ExtendedISOLanguageCodeType-V0-4.xsd"/>

    <xs:import
    namespace="http://www.wipo.int/standards/XMLSchema/Common/0"
    schemaLocation="ST96AnnexIIISchemas-V0-11/Common/0/Basic/ExtendedISOCurrencyCodeType-V0-1.xsd"/>


    These files include some other xsd files.

    After all this base.xsd defines

    <xs:simpleType name="tCountryCodes">
    <xs:union memberTypes="com:ExtendedWIPOST3CodeType" />
    </xs:simpleType>

    <xs:simpleType name="tLangs">
    <xs:union memberTypes="com:ExtendedISOLanguageCodeType" />
    </xs:simpleType>

    <xs:simpleType name="tCurrencyCodes">
    <xs:union memberTypes="com:ExtendedISOCurrencyCodeType" />
    </xs:simpleType>


    when I use the following python code: schema = xmlschema.XMLSchema(xsd_path) I get the following error:


    Error: unknown type '{http://www.wipo.int/standards/XMLSchema/Common/0}ExtendedISOLanguageCodeType'
    ​

    which is defined in ST96AnnexIIISchemas-V0-11/Common/0/Basic/ExtendedISOLanguageCodeType-V0-4.xsd as:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:com="http://www.wipo.int/standards/XMLSchema/Common/0"
    targetNamespace="http://www.wipo.int/standards/XMLSchema/Common/0"
    elementFormDefault="qualified"
    attributeFormDefault="qualified" version="0.4">
    <xsd:include schemaLocation="ISOLanguageCodeType-V0-1.xsd"/>
    <xsd:include schemaLocation="ISOFormerLanguageCodeType-V0-1.xsd"/>
    <xsd:simpleType name="ExtendedISOLanguageCodeType">
    <xsd:union memberTypes="com:ISOLanguageCodeType com:ISOFormerLanguageCodeType"/>
    </xsd:simpleType>
    </xsd:schema>


    As you can notice there is no issue with com:ExtendedWIPOST3CodeType whose definition precedes com:ExtendedISOLanguageCodeType

    The xs:schema of base.xsd comprises xmlns:com="http://www.wipo.int/standards/XMLSchema/Common/0". I check all the xmlns and targetNamespace.

    If I change base.xsd to:

    <xs:import
    namespace="http://www.wipo.int/standards/XMLSchema/Common/0"
    schemaLocation="ST96AnnexIIISchemas-V0-11/Common/0/Basic/ExtendedWIPOST3CodeType-V0-3.xsd"/>

    <xs:import
    namespace="http://www.wipo.int/standards/XMLSchema/Common/0"
    schemaLocation="ST96AnnexIIISchemas-V0-11/Common/0/Basic/ExtendedISOLanguageCodeType-V0-4.xsd"/>

    <xs:import
    namespace="http://www.wipo.int/standards/XMLSchema/Common/0"
    schemaLocation="ST96AnnexIIISchemas-V0-11/Common/0/Basic/ExtendedISOCurrencyCodeType-V0-1.xsd"/>

    <xs:simpleType name="tCountryCodes">
    <xs:union memberTypes="com:ExtendedWIPOST3CodeType"/>
    </xs:simpleType>

    <xs:simpleType name="tLangs">
    <!--
    <xs:union memberTypes="com:ExtendedISOLanguageCodeType"/>
    -->
    <xs:restriction base="xs:string"/>
    </xs:simpleType>

    <xs:simpleType name="tCurrencyCodes">
    <!--
    <xs:union memberTypes="com:ExtendedISOCurrencyCodeType"/>
    -->
    <xs:restriction base="xs:string"/>
    </xs:simpleType>


    The xsd is well loaded and used.

    The exact same xsd is accepted by dotnet 8 code.

    What can I do from here to avoid the error ?

    Continue reading...

Compartilhe esta Página