【问题标题】:pyxb issues with assigning vlaues to anunbound inner complex element with known typepyxb 将值分配给具有已知类型的未绑定内部复杂元素的问题
【发布时间】:2015-02-06 18:28:09
【问题描述】:

我正在尝试将值分配给预定义类型的未绑定内部元素,但我无法验证它。 这是我的示例,带有 reports.xsd 和不工作的代码的 sn-p: ...

   <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

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

【问题讨论】:

  • 谢谢 - 它也对我有用。

标签: python pyxb


【解决方案1】:

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

这一行:

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

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

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

rep.reportingGroups.append(reports.ReportingGroupType(title='not name', id='A1'))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-15
    • 2021-01-06
    • 1970-01-01
    • 1970-01-01
    • 2011-02-08
    • 1970-01-01
    • 2019-06-20
    相关资源
    最近更新 更多