The absence of a datum in XML can be expressed either by omitting the element (minOccurs="0" in schema) or by setting it to xsi:nil="true" (nillable=true in schema).

Using minOccurs=0 seem altogether cleaner and more consistent, and it doesn't require the XML to reference the XSD namespace. So what is the benefit of nillable?


nillable is in the spec because the XML Schema WG had a number of members who saw the world in SQL terms and wanted an explicit equivalent to SQL's null values. It's totally unnecessary in my view: just ignore it and don't use it.

| improve this answer | |
  • When nillable="true" is useful : ibm.com/developerworks/library/ws-tip-null/#N100FA – Laiv May 15 '17 at 10:03
  • 1
    @Laiv: You could just as well represent it as <elem><nil /></elem>. But I can see how xsd:nil makes sense in a certain way of thinking, since you can have data types orthogonal to the structure of the XML. – JacquesB May 15 '17 at 13:26
  • If you know that someone has four sons and you don't know the name of the third son, then one way of representing it is <son>Matthew</son><son>Mark</son><son/><son>John</son>. But in general, if you want to model "partial information", then I think you usually want to record something about it, e.g. "unknown" or "not applicable" or "deleted". Invent your own vocabulary to fit the semantics of your particular data. – Michael Kay May 15 '17 at 16:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.