Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XS Element mandatory/required

 
thomas davis
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<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.

Thanks

[edit by moderator: changed from all caps subject line to mixed case]
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
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
Posts: 207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic