【发布时间】:2015-04-27 18:12:43
【问题描述】:
我正在尝试将一个名为 nbReports 的内部 nillable 元素设置为 null,但到目前为止我失败了。
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 name="nbReports" type="xs:int" nillable="true"/>
</xs:sequence>
<xs:attribute name="id" type="xs:ID" use="required"/>
</xs:complexType>
代码截图:
import reports
rep=reports.reports()
rep.description="this report is ..."
temp=ReportingGroupType(id=xs.string("A1")
temp.title="this title")
temp.nbReports._setIsNil #"error: AttributeError: 'NoneType' object has no attribute '_setIsNil'
如果我尝试将 nbReports 设置为任何值(例如 4)以创建 nbReprots 的实例,然后将其设置为 null,则打印时 nbReprots 值将保持为 4。
【问题讨论】:
-
对于 XSD 中的
nillable="true"是 XML 文件中带有nil="true"的节点上的属性的节点,我收到的信息。请注意,它是一个属性,而不是节点的内容。例如,如果我有一个<xs:element name="void_date" nillable="true"/>的 XSD 声明,那么我收到的 XML 是<void_date nil="true"/>。 -
我明白你的意思。我的下一个问题是,如果我的元素 nbReports 是 reportingGroupType 的子元素,如何将 nil 属性设置为 true?