Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of XMLElement@required=true

Tags:

jax-ws

cxf

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.

like image 279
sateesh Avatar asked Oct 04 '12 14:10

sateesh


1 Answers

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

like image 70
CodeClimber Avatar answered Sep 20 '22 13:09

CodeClimber