0

I am trying to set an inner nillable element called nbReports to null and so far I have failed.

A snapshot of the XSD file and the code is next:

<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>

The code snapshot:

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'

If I try to set nbReports to any value (e.g. 4) to create an instance of nbReprots and then I set it to null then nbReprots value will remain 4 when I print it.

PhillyNJ
  • 3,859
  • 4
  • 38
  • 64
malika
  • 1
  • What I receive for nodes where `nillable="true"` in the XSD is an attribute on the node with `nil="true"` in the XML file. Note it's an *attribute*, not the node's content. For instance, if I have an XSD declaration for ``, then the XML I receive is ``. – Ken White Feb 25 '15 at 18:32
  • I see your point. My next question is how to set nil attribute to true in the case of my element nbReports that is a child of reportingGroupType? – malika Feb 25 '15 at 19:36

1 Answers1

0

First of all you need to bind the element with pyxb.BIND()

Based on Ken's comments I was able to set nil attribute to true :

temp.nbReports=pyxb.BIND()
temp.nbReports._setIsNil(nil=True)

Thank you for your help.

Malika

NKSM
  • 5,422
  • 4
  • 25
  • 38
malika
  • 1