users@jaxb.java.net

Re: JAXB Unmarshalling error unexpected element

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Sat, 30 Jan 2010 18:29:58 +0100

Well, the schema is OK, and I have no problem unmarshalling the snippet
you mailed in your 1st posting using code generated from it. But note
that the stack trace points out an error in line 14, whereas your XML only
has 6 lines.

Also, I'd recommend that you use validation against the XML schema
during unmarshalling, which is easy to set up.

Another question due to your sentence:

"I have a file called arc-permissions.xml containing the permissions element
that is passed into the system and it is cast to a arcdb."

What do you mean by "casting a file to a arcdb"??

-W

On Fri, Jan 29, 2010 at 7:03 PM, cobrab <ben.facker_at_gmail.com> wrote:
>
>
>
> What is this "other class" with output-value,... setpoints? Any
> chance it can be confused with com.myProgram.arc.schema.CustomerModes?
>
> Somehow you must have created an alternative for interpreting a
> <permissions> element that's not based on the schema, where
> <permissions> is subordinate to <arcdb>.
>
> This leads to another question: What do you mean by "I am giving it an
> element such as..."? An XML containing just <permissions/> cannot
> be unmarshalled against the schema you've posted.
>
> -W
>
> W, thanks for the reply.  The class that it is trying to pull elements from
> is called ArcChannel which is defined by channel in the schema.
> Customer-modes is not the problem.  Sorry I didn't include channel in the
> xsd exerpt.  I have added the entire file below.
>
> I have a file called arc-permissions.xml containing the permissions element
> that is passed into the system and it is cast to a arcdb.  It is when
> unmarshaling the arc-permissions.xml that I get the error.
>
> The java implimentation for this is:
>
>                        File input1 = new File(name);//which is arc-permissions.xml
>                        if (input1.exists() == false) {
>                                return null;
>                        }
>                        Arcdb contents =  (Arcdb)this.xmlService.unmarshal(input1);
>                        return contents;
>
> xmlService just calls unmarshal on the file.
>
>
> Full xsd file:
>
> <?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:annotation>
>                <xs:documentation xml:lang="en">
>                        Controller Communication Protocol version 1.0.0.
>                </xs:documentation>
>        </xs:annotation>
>
>        <xs:element name="arc-packet">
>                <xs:complexType>
>                        <xs:sequence>
>                                <xs:element name="header" type="arc:header" minOccurs="1"
> maxOccurs="1"/>
>                                <xs:choice  minOccurs="1" maxOccurs="unbounded">
>                                        <xs:element name="request" type="arc:request"/>
>                                        <xs:element name="response" type="arc:response"/>
>                                </xs:choice>
>                        </xs:sequence>
>                        <xs:attribute name="id" type="xs:string" use="optional"/>
>                </xs:complexType>
>        </xs:element>
>
>        <xs:element name="command-abf">
>                <xs:complexType>
>                        <xs:choice minOccurs="1" maxOccurs="1">
>                                <xs:element name="command-batch" type="arc:command-batch"/>
>                                <xs:element name="sequence" type="arc:sequence"/>
>                        </xs:choice>
>                </xs:complexType>
>        </xs:element>
>
>        <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:element name="configuration">
>                <xs:complexType>
>                        <xs:complexContent>
>                                <xs:extension base="arc:configuration"/>
>                        </xs:complexContent>
>                </xs:complexType>
>        </xs:element>
>
>        <xs:simpleType name="response-codes">
>                <xs:restriction base="xs:string">
>                        <xs:enumeration value="OK"/>
>                        <xs:enumeration value="FAILURE"/>
>                        <xs:enumeration value="NOT_CONNECTED"/>
>                        <xs:enumeration value="ERROR"/>
>                        <xs:enumeration value="QBIT"/>
>                        <xs:enumeration value="UNAUTHORIZED"/>
>                </xs:restriction>
>        </xs:simpleType>
>
>        <xs:simpleType name="function-types">
>                <xs:restriction base="xs:string">
>                        <xs:enumeration value="connect"/>
>                        <xs:enumeration value="ping"/>
>                        <xs:enumeration value="disconnect"/>
>                        <xs:enumeration value="get-diagnostics"/>
>                        <xs:enumeration value="get-current-values"/>
>                        <xs:enumeration value="get-channel-value"/>
>                        <xs:enumeration value="start"/>
>                        <xs:enumeration value="abort"/>
>                        <xs:enumeration value="get-configuration"/>
>                        <xs:enumeration value="get-calibration"/>
>                        <xs:enumeration value="get-command-sequence"/>
>                        <xs:enumeration value="get-execution-status"/>
>                        <xs:enumeration value="set-configuration"/>
>                        <xs:enumeration value="set-calibration"/>
>                        <xs:enumeration value="load-command-batch"/>
>                        <xs:enumeration value="get-command-library-list"/>
>                        <xs:enumeration value="get-command-library"/>
>      <xs:enumeration value="get-access-log" />
>                </xs:restriction>
>        </xs:simpleType>
>
>        <xs:element name="function-set">
>                <xs:complexType>
>                        <xs:choice minOccurs="1" maxOccurs="unbounded">
>                                <xs:element name="function" type="arc:function-types"/>
>                        </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="downlink"/>
>                        <xs:enumeration value="fullcontrol"/>
>                </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="authorization">
>                <xs:attribute name="function" type="arc:function-types"/>
>        </xs:complexType>
>
>        <xs:simpleType name="value-types">
>                <xs:restriction base="xs:string">
>                        <xs:enumeration value="eu"/>
>                        <xs:enumeration value="percent"/>
>                        <xs:enumeration value="raw"/>
>                </xs:restriction>
>        </xs:simpleType>
>
>        <xs:simpleType name="batch-mode">
>                <xs:restriction base="xs:string">
>                        <xs:enumeration value="NO_BATCH_LOADED"/>
>                        <xs:enumeration value="INITIALIZED"/>
>                        <xs:enumeration value="STARTED"/>
>                        <xs:enumeration value="COMPLETED"/>
>                        <xs:enumeration value="ABORTED_OPERATOR"/>
>                        <xs:enumeration value="ABORTED_CLIENT"/>
>                        <xs:enumeration value="ABORTED_ERROR"/>
>                        <xs:enumeration value="ABORTED_HEARTBEAT"/>
>                </xs:restriction>
>        </xs:simpleType>
>
>        <xs:complexType name="header">
>                <xs:sequence>
>                        <xs:element name="version" type="xs:string" minOccurs="1" maxOccurs="1"/>
>                        <xs:element name="timestamp" type="xs:dateTime" minOccurs="1"
> maxOccurs="1"/>
>                        <xs:element name="customer" type="arc:customer" minOccurs="1"
> maxOccurs="1"/>
>                        <xs:element name="client-mac" type="xs:string" minOccurs="1"
> maxOccurs="1"/>
>                        <xs:element name="session" type="arc:session" minOccurs="1"
> maxOccurs="1"/>
>                </xs:sequence>
>        </xs:complexType>
>
>        <xs:complexType name="customer">
>                <xs:attribute name="guid" type="xs:string" use="required"/>
>        </xs:complexType>
>
>        <xs:complexType name="session">
>                <xs:attribute name="guid" type="xs:string" use="required"/>
>                <xs:attribute name="ip" type="xs:string" use="optional"/>
>        </xs:complexType>
>
>  <xs:complexType name="request">
>    <xs:sequence>
>      <xs:element name="function" type="arc:function-types" minOccurs="1"
> maxOccurs="1" />
>      <xs:choice minOccurs="0" maxOccurs="1">
>        <xs:element name="calibration" type="arc:calibration" />
>        <xs:element name="configuration" type="arc:configuration" />
>        <xs:element name="diagnostics" type="arc:diagnostics" />
>        <xs:element name="command-batch" type="arc:command-batch" />
>        <xs:element name="current-values" type="arc:current-values" />
>        <xs:element name="access-log" type="arc:access-log" />
>        <xs:element name="channel-id" type="xs:integer" />
>        <xs:element name="mode" type="arc:application-modes" minOccurs="1"
> maxOccurs="1" />
>      </xs:choice>
>    </xs:sequence>
>    <xs:attribute name="id" type="xs:string" use="required" />
>  </xs:complexType>
>
>  <xs:complexType name="response">
>    <xs:sequence>
>      <xs:element name="function" type="arc:function-types" minOccurs="1"
> maxOccurs="1" />
>      <xs:element name="response-code" type="arc:response-codes"
> minOccurs="1" maxOccurs="1" />
>      <xs:element name="response-message" type="xs:string" minOccurs="1"
> maxOccurs="1" />
>      <xs:choice minOccurs="0" maxOccurs="1">
>        <xs:element name="calibration" type="arc:calibration" />
>        <xs:element name="configuration" type="arc:configuration" />
>        <xs:element name="diagnostics" type="arc:diagnostics" />
>        <xs:element name="command-batch" type="arc:command-batch" />
>        <xs:element name="current-values" type="arc:current-values" />
>        <xs:element name="access-log" type="arc:access-log" />
>      </xs:choice>
>      <xs:element name="status" type="arc:status" minOccurs="0"
> maxOccurs="1" />
>    </xs:sequence>
>    <xs:attribute name="id" type="xs:string" use="required" />
>  </xs:complexType>
>
>        <xs:complexType name="calibration">
>                <xs:sequence>
>                        <xs:element name="channel-calib" type="arc:channel-calib" minOccurs="1"
> maxOccurs="unbounded"/>
>                </xs:sequence>
>                <xs:attribute name="id" type="xs:string" use="optional"/>
>                <xs:attribute name="persisted" type="xs:boolean" use="optional"/>
>        </xs:complexType>
>
>        <xs:complexType name="channel-calib">
>                <xs:sequence>
>                        <xs:element name="calib-point" type="arc:calib-point" minOccurs="1"
> maxOccurs="unbounded"/>
>                </xs:sequence>
>                <xs:attribute name="id" type="xs:integer" use="required"/>
>                <xs:attribute name="last-calibrated" type="xs:dateTime" use="required"/>
>        </xs:complexType>
>
>        <xs:complexType name="calib-point">
>                <xs:attribute name="raw" type="xs:decimal" use="required"/>
>                <xs:attribute name="eu" type="xs:decimal" use="required"/>
>        </xs:complexType>
>
>        <xs:complexType name="configuration">
>                <xs:sequence>
>                        <xs:element name="channel-config" type="arc:channel-config" minOccurs="1"
> maxOccurs="unbounded"/>
>                </xs:sequence>
>                <xs:attribute name="id" type="xs:string" use="optional"/>
>                <xs:attribute name="persisted" type="xs:boolean" use="optional"/>
>        </xs:complexType>
>
>        <xs:complexType name="channel-config">
>                <xs:sequence>
>                        <xs:element name="units" type="xs:string" minOccurs="1" maxOccurs="1"/>
>                        <xs:element name="limit-high" type="arc:limit-high" minOccurs="1"
> maxOccurs="1"/>
>                        <xs:element name="setpoint" type="arc:setpoint" minOccurs="1"
> maxOccurs="1"/>
>                </xs:sequence>
>                <xs:attribute name="id" type="xs:integer" use="required"/>
>                <xs:attribute name="name" type="xs:string" use="required"/>
>                <xs:attribute name="mirrorChannel" type="xs:integer" use="required"/>
>                <xs:attribute name="last-configured" type="xs:dateTime" use="required"/>
>        </xs:complexType>
>
>        <xs:complexType name="versioned-component">
>                <xs:attribute name="version" type="xs:string" use="required"/>
>                <xs:attribute name="online" type="xs:boolean" use="required"/>
>        </xs:complexType>
>
>        <xs:simpleType name="command-types">
>                <xs:restriction base="xs:string">
>                        <xs:enumeration value="step"/>
>                        <xs:enumeration value="slope"/>
>                </xs:restriction>
>        </xs:simpleType>
>
>        <xs:complexType name="value">
>                <xs:attribute name="value" type="xs:decimal" use="required"/>
>                <xs:attribute name="value-type" type="arc:value-types" use="required"/>
>        </xs:complexType>
>
>        <xs:complexType name="limit-high">
>                <xs:complexContent>
>                        <xs:extension base="arc:value"/>
>                </xs:complexContent>
>        </xs:complexType>
>
>        <xs:complexType name="setpoint">
>                <xs:complexContent>
>                        <xs:extension base="arc:value"/>
>                </xs:complexContent>
>        </xs:complexType>
>
>        <xs:complexType name="diagnostics">
>                <xs:sequence>
>                        <xs:element name="arc-name" type="xs:string" minOccurs="1"
> maxOccurs="1"/>
>                        <xs:element name="arc-service" type="arc:versioned-component"
> minOccurs="1" maxOccurs="1"/>
>                        <xs:element name="arc-plc" type="arc:versioned-component" minOccurs="1"
> maxOccurs="1"/>
>                        <xs:element name="v-daq" type="arc:versioned-component" minOccurs="1"
> maxOccurs="1"/>
>                        <xs:element name="channels" type="arc:channels" minOccurs="1"
> maxOccurs="1"/>
>                </xs:sequence>
>        </xs:complexType>
>
>        <xs:complexType name="channels">
>                <xs:sequence>
>                        <xs:element name="channel" type="arc:channel" minOccurs="1"
> maxOccurs="unbounded"/>
>                </xs:sequence>
>                <xs:attribute name="id" type="xs:string" use="required"/>
>        </xs:complexType>
>
>        <xs:complexType name="channel">
>                <xs:sequence>
>                        <xs:element name="setpoint" type="arc:setpoint" minOccurs="1"
> maxOccurs="1"/>
>                        <xs:element name="limit-high" type="arc:limit-high" minOccurs="0"
> maxOccurs="1"/>
>                        <xs:element name="command-value" type="arc:value" minOccurs="0"
> maxOccurs="1"/>
>                        <xs:element name="input-value" type="arc:value" minOccurs="0"
> maxOccurs="1"/>
>                        <xs:element name="output-value" type="arc:value" minOccurs="0"
> maxOccurs="1"/>
>                </xs:sequence>
>                <xs:attribute name="id" type="xs:integer" use="required"/>
>                <xs:attribute name="name" type="xs:string" use="required"/>
>                <xs:attribute name="units" type="xs:string" use="optional"/>
>                <xs:attribute name="session" type="xs:string" use="optional"/>
>                <xs:attribute name="executeFlag" type="xs:boolean" use="optional"/>
>                <xs:attribute name="mirrorFlag" type="xs:boolean" use="optional"/>
>                <xs:attribute name="last-calibrated" type="xs:dateTime" use="optional"/>
>                <xs:attribute name="last-configured" type="xs:dateTime" use="optional"/>
>                <xs:attribute name="last-command-load" type="xs:dateTime" use="optional"/>
>        </xs:complexType>
>
>        <xs:complexType name="status">
>                <xs:sequence>
>                        <!-- the following are for heartbeat / runswitch "online" queries -->
>                        <xs:element name="arc-plc-heartbeat" type="arc:versioned-component"
> minOccurs="1" maxOccurs="1"/>
>                        <xs:element name="arc-runswitch" type="arc:versioned-component"
> minOccurs="1" maxOccurs="1"/>
>                        <!-- these are for indicating error conditions -->
>                        <xs:element name="arc-plc-error" type="arc:arc-error" minOccurs="0"
> maxOccurs="1"/>
>                        <xs:element name="arc-vdaq-error" type="arc:arc-error" minOccurs="0"
> maxOccurs="1"/>
>                </xs:sequence>
>        </xs:complexType>
>
>        <xs:complexType name="arc-error">
>                <xs:attribute name="error-guid" type="xs:string" use="required"/>
>                <xs:attribute name="message" type="xs:string" use="required"/>
>        </xs:complexType>
>
>        <xs:complexType name="current-values">
>                <xs:sequence>
>                        <xs:element name="channel-value" type="arc:channel" minOccurs="1"
> maxOccurs="unbounded"/>
>                </xs:sequence>
>                <xs:attribute name="id" type="xs:string" use="optional"/>
>        </xs:complexType>
>
>        <xs:complexType name="command-batch">
>                <xs:sequence>
>                        <xs:element name="sequence" type="arc:sequence" minOccurs="1"
> maxOccurs="unbounded"/>
>                </xs:sequence>
>                <xs:attribute name="percentComplete" type="xs:decimal" use="optional"/>
>                <xs:attribute name="batchState" type="arc:batch-mode" use="optional"/>
>
>                <xs:attribute name="name" type="xs:string" use="required"/>
>                <xs:attribute name="id" type="xs:string" use="required"/>
>        </xs:complexType>
>
>        <xs:complexType name="sequence">
>                <xs:sequence>
>                        <xs:element name="channel-value" type="arc:value" minOccurs="0"
> maxOccurs="1"/>
>                        <xs:element name="command" type="arc:command" minOccurs="0"
> maxOccurs="unbounded"/>
>                </xs:sequence>
>                <xs:attribute name="name" type="xs:string" use="optional"/>
>                <xs:attribute name="id" type="xs:string" use="required"/>
>                <xs:attribute name="channel-id" type="xs:integer" use="optional"/>
>                <xs:attribute name="current-command" type="xs:string" use="optional"/>
>                <xs:attribute name="percentComplete" type="xs:decimal" use="optional"/>
>        </xs:complexType>
>
>        <xs:complexType name="command">
>                <xs:complexContent>
>                        <xs:extension base="arc:value">
>                                <xs:attribute name="id" type="xs:string" use="required"/>
>                                <xs:attribute name="type" type="arc:command-types" use="required"/>
>                                <xs:attribute name="duration" type="xs:decimal" use="required"/>
>                                <xs:attribute name="percent-complete" type="xs:decimal" use="optional"/>
>                        </xs:extension>
>                </xs:complexContent>
>        </xs:complexType>
>
>  <xs:complexType name="access-log">
>    <xs:sequence>
>      <xs:element name="logs" type="arc:logs" />
>    </xs:sequence>
>    <xs:attribute name="id" type="xs:string" />
>  </xs:complexType>
>  <xs:complexType name="logs">
>    <xs:attribute name="passkey" type="xs:string" use="required" />
>    <xs:attribute name="records" type="xs:decimal" use="required" />
>    <xs:attribute name="memo" type="xs:string" use="required" />
>    <xs:attribute name="id" type="xs:string" use="required" />
>  </xs:complexType>
>
> </xs:schema>
>
>
>
> --
> View this message in context: http://old.nabble.com/JAXB-Unmarshalling-error-unexpected-element-tp27361412p27375940.html
> Sent from the java.net - jaxb users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>