Does it mean the XML element is mandatory ? Or the XML element must have some non-null value ? I am really confused by the javadoc explanation.
Asked
Active
Viewed 2.9k times
2 Answers
18
@XMLElement(required=true)
generates something like this in the XML schema:
<xs:element name="city" type="xs:string" minOccurs="1"/>
which means the element and a value are mandatory. The default is false.
This:
@XMLELement(nillable=true)
generates something like this in the XML schema:
<xs:element name="city" type="xs:string" nillable="true"/>
which means you can pass in a nil value in your XML like this:
<city xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
Combining the two like this:
@XMLELement(nillable=true, required=true)
gives an XML schema definition similar to this:
<xs:element name="city" type="xs:string" nillable="true"/>
which means the element is mandatory but you can pass in a nil value.

CodeClimber
- 4,584
- 8
- 46
- 55
5
The minOccurs
indicator specifies the minimum number of times an element can occur. If element in the schema has minOccurs="1"
attribute this means that the element is mandatory. It must appear in the XML
document.

Paulius Matulionis
- 23,085
- 22
- 103
- 143
-
Thanks for taking time to dig into my question. I have clarified by creating a simple test harness. The mandatory constraint applies to both the element and its value. – sateesh Oct 08 '12 at 09:31