Parse an xml with Generateds and external references

The xml is VALID, the error I get is when I try to parse the xml with the classes generated with Generateds.

So, I´m generating classes for an xsd that has external xmlns. I generate the classes this way:

python generateDS.py -o cc.py --external-encoding='utf-8' --export="write etree" cc.xsd

I generate an minimalistic xml to valid the xsd and the xml valids the schema ( I validate it with lxml)

So the error occurs when I try to parse the xml. And ONLY if I include an element of the external reference. It gives me the next error:

TypeError: expected string or bytes-like object

I tried using --namespacedef= in the creation of the classes but the error is the same.

The external 'types' needed to parse the xml are generated in the .py.

I read that 'one per' may be a solution but I don´t quite get it.

xml:

<?xml version='1.0' encoding='UTF-8'?>
<dcc:digitalCalibrationCertificate xmlns:dcc="https://ptb.de/dcc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:si="https://ptb.de/si" xmlns:ext="extension" schemaVersion="3.0.0" xsi:schemaLocation="https://ptb.de/dcc https://ptb.de/dcc/v3.0.0/dcc.xsd">
    <dcc:result>        
        <dcc:data>
            <dcc:quantity>
                <si:real>
                    <si:value>150.16</si:value>
                    <si:unit>\degreeCelsius</si:unit>
                </si:real>
            </dcc:quantity>
        </dcc:data>
    </dcc:result>
</dcc:digitalCalibrationCertificate>

xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema version="3.0.0" xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:dcc="https://ptb.de/dcc"
           xmlns:si="https://ptb.de/si"
           targetNamespace="https://ptb.de/dcc"
           elementFormDefault="qualified">

    <xs:import
            namespace="https://ptb.de/si"
            schemaLocation="https://ptb.de/si/v2.0.0/SI_Format.xsd"/>

    <xs:element name="digitalCalibrationCertificate" type="dcc:digitalCalibrationCertificateType"/>

    <xs:complexType name="digitalCalibrationCertificateType">
        <xs:sequence>
            <xs:element name="result" type="dcc:resultType"/>
        </xs:sequence>

        <xs:attribute name="schemaVersion" use="required">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:pattern value="3\.0\.0"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:attribute>
    </xs:complexType>

    <xs:complexType name="resultType">
        <xs:annotation>
            <xs:documentation>
                The actual result of the calibration.
            </xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="data" type="dcc:dataType"/>
        </xs:sequence>
        <xs:attribute name="id" type="xs:ID" use="optional"/>
        <xs:attribute name="refId" type="xs:IDREF" use="optional"/>
        <xs:attribute name="refType" type="xs:string" use="optional"/>
    </xs:complexType>

    <xs:complexType name="dataType">
        <xs:choice maxOccurs="unbounded">
            <xs:element name="quantity" type="dcc:quantityType"/>
        </xs:choice>
        <xs:attribute name="id" type="xs:ID" use="optional"/>
        <xs:attribute name="refId" type="xs:IDREF" use="optional"/>
        <xs:attribute name="refType" type="xs:string" use="optional"/>
    </xs:complexType>

    <xs:complexType name="quantityType">
        <xs:sequence>
            <xs:choice>
                <xs:element ref="si:real"/>
                <xs:element ref="si:list"/>
                <xs:element ref="si:hybrid"/>
                <xs:element ref="si:complex"/>
                <xs:element ref="si:constant"/>
            </xs:choice>
        </xs:sequence>
        <xs:attribute name="id" type="xs:ID" use="optional"/>
        <xs:attribute name="refId" type="xs:IDREF" use="optional"/>
        <xs:attribute name="refType" type="xs:string" use="optional"/>
    </xs:complexType>
</xs:schema>

Upvotes: 0

Views: 329

Answers (0)

Related Questions