Attributes of the nillable and minOccurs XSD Element

I go back and forth with setting the element to minOccurs="0" and nillable="true" .

I read this article and now in my WSDL I'm not sure if using both is worth it. The article presents a good example of the representation of arrays, where you can have null values ​​interspersed throughout, since this cannot be done only with minOccurs="0" . Now, the convention I came across is that if an element is not optional, it is not nillable. The difference, as far as I understand, and where my question is, by applying the nillable property to the element, I say that you can pass the XSD equivalent to NULL? Otherwise, an element without the nillable property must have a value within the limits set on it?

+34
wsdl xml xsd
Dec 14 '09 at 19:50
source share
1 answer

You need to decide whether you think of XML as XML or whether you think of XML as a way to pass a Java (or other) object from here to it.

In XML, nillable enables the <myelement xsi:nil='true'/> construct as an indicator of an explicitly missing value, such as SQL NULL. This is semantically different from just <myelement/> . And both are different from nothing. Therefore, looking at XML, you should distinguish four cases:

 <!-- nothing --> <myElement attr1='true'>some content</myElement> <myElement/> <myElement xsi:nil='true'/> 

If, on the other hand, you are primarily involved in Java - perhaps because you use SOAP, then you need to think about how the Java object moves back and forth.

For any Java element that inherits from Object, JAXB and other matching technologies need a way to handle null values. Nillable is a way to do this. If you refuse anything that might be an object, the tools will annoyingly use an array to find a way to represent the absence.

On the other hand, if you have an array, keep in mind that the array itself is an object and may be null. Thus, each toolkit should distinguish an array of zero elements from zero.

On the other hand, if you have a primitive type (e.g. int ), nillable will lead to problems because there is no mapping from xsi: nil to the primitive.

+55
Dec 14 '09 at 19:59
source share



All Articles