Hi,
I am getting an error while parsing(unmarshallling) the xml using JAXB thru XSD validation.
Here is the
xsd, that I am using for the validation followed by the xml sample and exception that I am getting.
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="process_variable_type">
<xs:sequence>
<xs:element name="variable_name" type="xs:string"/>
<xs:element name="label" type="xs:string"/>
<xs:element name="value" type="xs:string"/>
<xs:element name="previous_value" type="xs:string"/>
<xs:element name="format" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="text_field_type">
<xs:complexContent>
<xs:extension base="process_variable_type">
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="part_type">
<xs:sequence>
<xs:choice>
<xs:element name="textFieldElement" type="text_field_type" />
</xs:choice>
</xs:sequence>
<xs:attribute name="name" type="xs:string" />
</xs:complexType>
<xs:element name="variable">
<xs:complexType>
<xs:sequence>
<xs:element name="part" type="part_type" minOccurs="1" maxOccurs="1" />
</xs:sequence>
<xs:attribute name="dataIncluded" type="xs:string" />
<xs:attribute name="hasData" type="xs:string" />
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="version" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:schema>
Sample XML:
<variable dataIncluded="yes" hasData="true" name="V1" version="25">
<part name="textFieldElement">
<textFieldElement xmlns="http://schemas.xmlsoap.org/ws/2003/03/business-process/" xmlns:abx="http://www.activebpel.org/bpel/extension" xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/" xmlns:ext="http://www.activebpel.org/2.0/bpel/extension" xmlns:ns1="urn:ValueDisplayer" xmlns:ns2="urn:ValueProvider" xmlns:ns3="Invalid Document" xmlns:ns4="http://temp" xmlns:ns5="http://active-endpoints.com/services/order" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<variable_name>Variable1</variable_name>
<label>Label2</label>
<value>Value1</value>
<previous_value>prevValue1</previous_value>
<format>format1</format>
<form_element_type>formElement1</form_element_type>
</textFieldElement>
</part>
</variable>
Error that I am getting is:
javax.xml.bind.UnmarshalException
- with linked exception:
[org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'textFieldElement'. One of '{"":textFieldElement}' is expected.]
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(AbstractUnmarshallerImpl.java:315)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.createUnmarshalException(UnmarshallerImpl.java:476)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:204)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:173)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:137)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:194)
at com.enfs.bpel.client.BpelClientUtility.unMarshal(BpelClientUtility.java:158)
at com.enfs.bpel.client.BpelClientUtility.main(BpelClientUtility.java:140)
Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'textFieldElement'. One of '{"":textFieldElement}' is expected.
at com.sun.org.apache.xerces.internal.jaxp.validation.Util.toSAXParseException(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.validation.ErrorHandlerAdaptor.error(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl.startElement(Unknown Source)
at com.sun.xml.bind.v2.runtime.unmarshaller.ValidatingUnmarshaller.startElement(ValidatingUnmarshaller.java:67)
at com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:117)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:200)
... 5 more
If I remove the following attribute in the textFieldElement from the sample, then I am able to unmarshal it successfully.
xmlns="http://schemas.xmlsoap.org/ws/2003/03/business-process/"
But at the runtime, I cannot avoid this attribute in the XML message which I should unmarshal it.
Need help to resolve this.
..Thiruppathy.R