Я пытаюсь установить внутренний элемент nillable, названный nbReports, равным null, и до сих пор я потерпел неудачу.Как установить внутренний элемент 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, когда я его распечатаю.
Что я получаю для узлов, где 'nillable =«истинный»' в XSD является атрибутом на узле с 'ноль =«истинный»' в файле XML. Обратите внимание, что это * атрибут *, а не содержимое узла. Например, если у меня есть объявление XSD для ' ', то XML, который я получаю, это ' '. –
Я вижу вашу точку зрения. Мой следующий вопрос: как установить атрибут nil в true в случае моего элемента nbReports, который является дочерним элементом reportGroupType? – malika