I'm trying to use jaxb 2.2 to unmarshal an xml configuration file, but I am
having trouble fixing an error. It seems as if the unmarshaller is binding
to the wrong class. The output-value, limit-high, command-high, and
setpoints are all values in another class. I've called the .toString method
on the JAXBContext instance and it is aware of all the classes I am trying
to use. Ff I give it an xml file without the proper elements the validator
gets angry and tells me I need to supply the correct format so it is aware
of the format the xml should be in. Any ideas would be appreciated.
I am giving it an element such as:
<permissions>
<customer-modes>
<customer guid=”XXXXXXXXXXX”/>
<application-mode id=”something”/>
</customer-modes>
</permissions>
Stacktrace from unmarshaller:
Line:Col[14:59]:unexpected element
(uri:"
http://www.myProgram.com/schemas/arc", local:"customer"). Expected
elements are
<{
http://www.myProgram.com/schemas/arc}output-value>,<{
http://www.myProgram.com/schemas/arc}limit-high>,<{
http://www.myProgram.com/schemas/arc}command-value>,<{
http://www.myProgram.com/schemas/arc}input-value>,<{
http://www.myProgram.com/schemas/arc}setpoint>
execption reading file /varco/data/configuration/Arc/arc-permissions.xml
com.myProgram.arc.error.ArcException: javax.xml.bind.UnmarshalException:
unexpected element (uri:"
http://www.myProgram.com/schemas/arc",
local:"customer"). Expected elements are
<{
http://www.myProgram.com/schemas/arc}output-value>,<{
http://www.myProgram.com/schemas/arc}limit-high>,<{
http://www.myProgram.com/schemas/arc}command-value>,<{
http://www.myProgram.com/schemas/arc}input-value>,<{
http://www.myProgram.com/schemas/arc}setpoint>
- Error while opening file:
/varco/data/configuration/Arc/arc-permissions.xml:com.myProgram.arc.error.ArcException:
javax.xml.bind.UnmarshalException: unexpected element
(uri:"
http://www.myProgram.com/schemas/arc", local:"customer"). Expected
elements are
<{
http://www.myProgram.com/schemas/arc}output-value>,<{
http://www.myProgram.com/schemas/arc}limit-high>,<{
http://www.myProgram.com/schemas/arc}command-value>,<{
http://www.myProgram.com/schemas/arc}input-value>,<{
http://www.myProgram.com/schemas/arc}setpoint>
- com.myProgram.arc.error.ArcException: javax.xml.bind.UnmarshalException:
unexpected element (uri:"
http://www.myProgram.com/schemas/arc",
local:"customer"). Expected elements are
<{
http://www.myProgram.com/schemas/arc}output-value>,<{
http://www.myProgram.com/schemas/arc}limit-high>,<{
http://www.myProgram.com/schemas/arc}command-value>,<{
http://www.myProgram.com/schemas/arc}input-value>,<{
http://www.myProgram.com/schemas/arc}setpoint>
at com.myProgram.arc.core.XmlService.unmarshal(XmlService.java:140)
at
com.myProgram.arc.core.FileBasedService.loadFile(FileBasedService.java:192)
the a sample of what I think are the pertinent parts of the xsd is:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="arc-protocol-1"
xmlns:xs="
http://www.w3.org/2001/XMLSchema"
xmlns:arc="
http://www.myProgram.com/schemas/arc"
targetNamespace="
http://www.myProgram.com/schemas/arc"
elementFormDefault="qualified">
<xs:element name="arcdb">
<xs:complexType>
<xs:choice>
<xs:element name="configuration" type="arc:configuration" minOccurs="1"
maxOccurs="1"/>
<xs:element name="calibration" type="arc:calibration" minOccurs="1"
maxOccurs="1"/>
<xs:element name="permissions" type="arc:permissions" minOccurs="1"
maxOccurs="1"/>
</xs:choice>
</xs:complexType>
</xs:element><xs:complexType name="permissions">
<xs:sequence>
<xs:element name="customer-modes" type="arc:customer-modes" minOccurs="1"
maxOccurs="unbounded"/>
<xs:element name="application-mode" type="arc:application-mode"
minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="application-mode">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="authorization" type="arc:authorization"/>
</xs:choice>
<xs:attribute name="id" type="arc:application-modes" use="required"/>
</xs:complexType>
<xs:simpleType name="application-modes">
<xs:restriction base="xs:string">
<xs:enumeration value="XXXX"/>
<xs:enumeration value="YYYY"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="customer-modes">
<xs:sequence>
<xs:element name="customer" type="arc:customer" minOccurs="1"
maxOccurs="1"/>
<xs:element name="application-mode" type="arc:application-mode"
minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="customer">
<xs:attribute name="guid" type="xs:string" use="required"/>
</xs:complexType>
</xs:schema>
Binding:
<jxb:bindings version="1.0"
xmlns:jxb="
http://java.sun.com/xml/ns/jaxb"
xmlns:xs="
http://www.w3.org/2001/XMLSchema"
schemaLocation="../schema/arc-protocol-1.0.0.xsd" node="/xs:schema">
<jxb:globalBindings>
<jxb:serializable/>
</jxb:globalBindings>
<jxb:schemaBindings>
<jxb:package name="com.myProgram.arc.schema"/>
</jxb:schemaBindings>
<jxb:bindings node="//xs:complexType[@name='customer']">
<jxb:class name="ArcCustomer"/>
</jxb:bindings>
<jxb:bindings node="//xs:complexType[@name='channel']">
<jxb:class name="ArcChannel"/>
</jxb:bindings>
<jxb:bindings node="//xs:complexType[@name='diagnostics']">
<jxb:class name="ArcDiagnostics"/>
</jxb:bindings>
<jxb:bindings node="//xs:complexType[@name='channels']">
<jxb:class name="ArcChannels"/>
</jxb:bindings>
<jxb:bindings node="//xs:complexType[@name='header']">
<jxb:class name="ArcHeader"/>
</jxb:bindings>
<jxb:bindings node="//xs:complexType[@name='session']">
<jxb:class name="ArcSession"/>
</jxb:bindings>
<jxb:bindings node="//xs:complexType[@name='request']">
<jxb:class name="ArcRequest"/>
</jxb:bindings>
<jxb:bindings node="//xs:complexType[@name='response']">
<jxb:class name="ArcResponse"/>
</jxb:bindings>
<jxb:bindings node="//xs:complexType[@name='configuration']">
<jxb:class name="ArcConfiguration"/>
</jxb:bindings>
<jxb:bindings node="//xs:complexType[@name='calibration']">
<jxb:class name="ArcCalibration"/>
</jxb:bindings>
<jxb:bindings node="//xs:complexType[@name='permissions']">
<jxb:class name="ArcPermissions"/>
</jxb:bindings>
<jxb:bindings node="//xs:complexType[@name='value']">
<jxb:class name="ArcValue"/>
</jxb:bindings>
<jxb:bindings node="//xs:complexType[@name='sequence']">
<jxb:class name="ArcSequence"/>
</jxb:bindings>
<jxb:bindings node="//xs:complexType[@name='command']">
<jxb:class name="ArcCommand"/>
</jxb:bindings>
<jxb:bindings node="//xs:complexType[@name='status']">
<jxb:class name="ArcStatus"/>
</jxb:bindings>
<jxb:bindings node="//xs:complexType[@name='access-log']">
<jxb:class name="ArcAccessLog"/>
</jxb:bindings>
</jxb:bindings>
--
View this message in context: http://old.nabble.com/JAXB-Unmarshalling-error-unexpected-element-tp27361412p27361412.html
Sent from the java.net - jaxb users mailing list archive at Nabble.com.