PyXB:无法分配正确的类型

2024-05-23 18:45:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用PyXB编辑使用以下模式文件的XML文件:http://www.opendrive.org/tools/OpenDRIVE_1.4H.xsd。我的python库名为OpenDrive14H.py。 我正在尝试将项目添加到列表“openDRIVE.lane.width”,定义如下:

            <!--lane.width -->  
        <xsd:element name="width" minOccurs="1" maxOccurs="unbounded">
            <xsd:complexType>

                <xsd:sequence>
                    <xsd:element name="userData" type="userData" minOccurs="0" maxOccurs="unbounded"/>
                    <xsd:element name="include"  type="include"  minOccurs="0" maxOccurs="unbounded"/>
                </xsd:sequence>

                <!--these 5 required on lane.width -->
                <xsd:attribute name="sOffset" type="xsd:double"/>
                <xsd:attribute name="a"       type="xsd:double"/>
                <xsd:attribute name="b"       type="xsd:double"/>
                <xsd:attribute name="c"       type="xsd:double"/>
                <xsd:attribute name="d"       type="xsd:double"/>
            </xsd:complexType>
        </xsd:element>

我尝试了3种方法来设置宽度

enter image description here

每个方法都会抛出一个SimpleTypeValueError。方法1和方法3直接在您看到的行中抛出异常。方法2稍后在“toxml”方法中抛出错误,其中opendrive是包含上述通道的文件

content = opendrive.toxml("utf-8").decode('utf-8')

lane.width的类型为<class 'pyxb.binding.content._PluralBinding'>,它的开头有0个元素。 我真的不理解这个例外,因为它说“A不可能是A”。我很高兴能得到一些帮助

问候


Tags: 文件方法nametypeattributeelementwidthxsd