0

我正在尝试将值分配给预定义类型的未绑定内部元素,但我无法验证它。这是我的报告.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>

import reports
rep=reports.reports()

rep.description="this report is ..." #works

rep.reportingGroups=pyxb.BIND()

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

print(rep.reportingGroups.toxml("utf-8"))  #does not work

我找不到与此类似的案例。我感谢您的帮助。马利卡

4

1 回答 1

0

如果您解释“不起作用”对您意味着什么,这将有所帮助。

这一行:

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

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

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

rep.reportingGroups.append(reports.ReportingGroupType(title='not name', id='A1'))
于 2015-02-11T18:33:01.767 回答