wood burning stoves
The moose likes Web Services and the fly likes XS Element mandatory/required Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "XS Element mandatory/required" Watch "XS Element mandatory/required" New topic

XS Element mandatory/required

thomas davis
Ranch Hand

Joined: Feb 01, 2003
Posts: 207
<xs:element name="RequestType" type="tns:Type" minOccurs="1" maxOccurs="1"/>

According to documentation for xs elements,it is not required to have minOccurs and maxOccurs set to "1",as "1" is default values for minOccurs and maxOccurs .

I am using my XSD for Webservice.When compile and run it,It does not show any validation for mandatory/required fields.It just pass through as if there is no mandatory check.I have alreay set minOccurs and maxOccurs to "1",It should give me some kind of validation,if I do not provide value for it.Am I right? Why its not taking consideration of this?

What changes I need to make RequestType mandatory or required in XSD?

When I go to generated class it shows as given below
@XmlElement(required = true)
protected Type requestType;

What is to be done for making this element mandatory and when I call without having value assigned to it,it should warn that this element is mandatory.


[edit by moderator: changed from all caps subject line to mixed case]
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
I assume that JAXB is responsible for marshalling and unmarshalling XML data and thus also responsible for validating the data.
You can try by trying to unmarshall some XML data which is incomplete.
For an example program, see page 288 in http://www.slideshare.net/krizsan/scdjws-5-study-notes-3085287
I am not entirely certain whether validation is turned on by default.
Best wishes!
thomas davis
Ranch Hand

Joined: Feb 01, 2003
Posts: 207
Everthing is working fine.I could use these elements to get and set values and also I am able to get simple type on it.

I do not find any error on it.

There should be some way to do it
I agree. Here's the link: http://aspose.com/file-tools
subject: XS Element mandatory/required
It's not a secret anymore!