pyxb将值分配给具有已知类型的内部复杂元素的问题

2024-04-26 20:45:29 发布

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

我试图将值赋给预定义类型的未绑定内部元素,但无法验证它。 这是我的例子报告.xsd以及不起作用的代码片段: ... 在

   <xs:element name="reports" type="tns:Reports"/>
<xs:complexType name="Reports">
    <xs:sequence>
        <xs:element minOccurs="0" name="description" type="xs:string"/>
        <xs:element minOccurs="0" name="reportingGroups">
            <xs:complexType>
                <xs:sequence>
                    <xs:element maxOccurs="unbounded" minOccurs="0"
                        name="reportingGroup" type="tns:ReportingGroupType"/>
                </xs:sequence>
            </xs:complexType>
        </xs:element>
    </xs:sequence>
</xs:complexType>
<xs:complexType name="ReportingGroupType">
    <xs:sequence>
        <xs:element name="title" type="xs:string"/>
        <xs:element minOccurs="0" name="description" type="xs:string"/>
    </xs:sequence>
    <xs:attribute name="id" type="xs:ID" use="required"/>
</xs:complexType>

^{pr2}$

我找不到一个和这件案子类似的案子。谢谢你的帮助。 马利卡


Tags: name类型stringtypedescriptionelementreportssequence
1条回答
网友
1楼 · 发布于 2024-04-26 20:45:29

如果你能解释一下“不起作用”对你意味着什么,那会有帮助。在

这条线:

rep.reportingGroups.append("ReportingGroupType(name='this title",id=xs.string("A1")) #works

很奇怪,对我不起作用,产生“无效的非元素内容”错误,因为字符串ReportingGroupType(name='this title不能解释为ReportingGroupType类型的元素。在

如果我用对象构造函数替换该字符串并更正其工作的从属元素的名称:

^{pr2}$

相关问题 更多 >