aspose file tools*
The moose likes XML and Related Technologies and the fly likes Is Nillable same as an empty element Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Is Nillable same as an empty element" Watch "Is Nillable same as an empty element" New topic
Author

Is Nillable same as an empty element

Rajani Gummadi
Ranch Hand

Joined: Dec 17, 2010
Posts: 48
Hi,

I have an xsd declared as below



From the above schema, I used nillable = "true" for person but not for organization. That means I believe, nillable = false (default) for organization.

What exactly does it mean?

I wrote an xml instance based on this schema as follows



and another instance


In either case, when I validated the xml it did not give me any error or warning. So what is nillable doing here and what is the real purpose of this attribute ?
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 535
    
    3
In either case, when I validated the xml it did not give me any error or warning.


[0] That shouldn't be the case. Both documents should be invalidated with the mention:
"...(organization | person) cannot be empty according to the DTD/Schema"
or something of the kind.

[1] For tns:organization, there is nothing we you do except complying to the schema by adding its children tns:organizationName and tns:organizationId, one each of that order with the correct text types.

[2] For tns:person, you can adding the attribute xsi:nil="true" and the document would be validated. And that is the major aspect of what nullible attribute being true meant in the schema.
Rajani Gummadi
Ranch Hand

Joined: Dec 17, 2010
Posts: 48
Hi,

I'm really not clear on the concept of nillable is true. What does it mean? and why did you all nill=true in xml instance.
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 535
    
    3
>and why did you all nill=true in xml instance
???

It would not be surprising if it is still not clear. You have to first validate your validation algorithm as you seem to suggest there were no error and warning in both of the original documents. That can't be true and in the case of tns:organization that is even obvious. Make sure that part it is clear to you and the part of nillable would have a chance to fit into the understanding more naturally.
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 535
    
    3
If I can direct you to the documentation, that may be helpful with the concrete cases here you can have adequate focus.
http://www.w3.org/TR/xmlschema-1/

2.6 Schema-Related Markup in Documents Being Validated

2.6.2 xsi:nil

XML Schema: Structures introduces a mechanism for signaling that an element should be accepted as ·valid· when it has no content despite a content type which does not require or even necessarily allow empty content. An element may be valid without content if it has the attribute xsi:nil with the value true. An element so labeled must be empty, but can carry attributes if permitted by the corresponding complex type.


The xs:nullable="true" in the schema document precisely allow the element in the document to be validated to acquire the schema instance attribute xsi:nil. If further it is set to true, empty content of that element will be treated as valid despite the content model of that element in the schema document.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Is Nillable same as an empty element