A web service illustrating how you can construct an XML document with XMLBeans and types compiled from schema. It also shows how you can validate the document in cases where your code may create a document that is invalid.
The schema for the document created by the sample, EmployeeMarital.xsd, defines a snippet of data about an employee that specifies their marital status (for example, "Married", "Single", or "Domestic partner"). The schema defines a "choice" structure in which only one of a set of elements is allowed. The set in this case includes partner-name and spouse-name elements. Only one of these would be applicable for a given employee, so only one should be allowed. However, to illustrate validation, the code here tries to add both.
Validation is done with the XmlObject.validate method, which in this case takes an XmlOptions argument. The option specifies an ArrayList as a "listener" to use for collecting errors that occur while validating -- but any object implementing the java.util.Collection interface will work for this purpose. During validation, the XMLBeans runtime components call the listener's add method as errors are discovered, adding XmlError instances that this code can use to record and report what happened with the validation.
This sample is located in the xmlBeans/schema folder of the SamplesApp WebLogic Workshop project. In the file system the location is:
BEA_HOME\weblogic81\samples\workshop\SamplesApp\WebServices\xmlBeans\schema\SchemaChoice.jws
To Run the Sample
BEA_HOME/weblogic81/samples/domains/workshop/startWebLogic.sh