我正在尝试将值分配给预定义类型的未绑定内部元素,但我无法对其进行验证。 这是我的reports.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
我无法找到与此类似的案例。我感谢您的帮助。 玛莉卡
答案 0 :(得分:0)
如果您解释“不起作用”对您意味着什么,那将会有所帮助。
这一行:
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'))