users@jaxb.java.net

RE: Re: Issue unmarshalling object...unexpected element

From: Anil Arora <aarora_at_interlacesystems.com>
Date: Mon, 22 Oct 2007 07:05:56 -0700

This is what that file contains...

@javax.xml.bind.annotation.XmlSchema(namespace =
"http://schemas.interlacesystems.com/jaxbtest/JAXBTest.xsd",
elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package com.interlacesystems.jaxbtest;



> -----Original Message-----
> From: Kenny MacLeod [mailto:kennym_at_kizoom.com]
> Sent: Monday, October 22, 2007 1:50 AM
> To: users_at_jaxb.dev.java.net
> Subject: Re: Issue unmarshalling object...unexpected element
>
> the namespace is usually specified in an annotation in the
> package-info.java file in the same package as the generated .java
> files.... is that there?
>
>
> Anil Arora wrote:
> > I am upgrading our application to use JDK 6u3. Along with it, I'm
> > upgrading from JAXB 1 to the JAXB implementation in JDK 6. However,
I'm
> > finding some strange issues when I am unmarshalling what should be
> > simple xml. I'm using xjc to generate the java objects so I'm not
doing
> > anything funny with annotations. It seems that the namespace is
messed
> > up in the generated code.
> >
> >
> >
> >
> >
> > javax.xml.bind.UnmarshalException: unexpected element
> > (uri:"http://schemas.interlacesystems.com/jaxbtest/JAXBTest.xsd",
> > local:"Description"). Expected elements are <{}Description>
> >
> > at
> >
>
com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.h
an
> dleEvent(UnmarshallingContext.java:523)
> >
> > at
> >
>
com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportError(Loa
de
> r.java:199)
> >
> > at
> >
>
com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportError(Loa
de
> r.java:194)
> >
> > at
> >
>
com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportUnexpecte
dC
> hildElement(Loader.java:71)
> >
> > at
> >
>
com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.childElement(Lo
ad
> er.java:65)
> >
> > at
> >
>
com.sun.xml.internal.bind.v2.runtime.unmarshaller.StructureLoader.childE
le
> ment(StructureLoader.java:209)
> >
> > at
> >
>
com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext._
st
> artElement(UnmarshallingContext.java:366)
> >
> > at
> >
>
com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.s
ta
> rtElement(UnmarshallingContext.java:347)
> >
> > at
> >
>
com.sun.xml.internal.bind.v2.runtime.unmarshaller.SAXConnector.startElem
en
> t(SAXConnector.java:101)
> >
> > at
> > org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown
Source)
> >
> > at
> >
org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown
> > Source)
> >
> > at
> >
>
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDis
pa
> tcher.dispatch(Unknown
> > Source)
> >
> > at
> >
>
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unkno
wn
> > Source)
> >
> > ...
> >
> >
> >
> >
> >
> > My xsd schema is...
> >
> >
> >
> > <?xml version="1.0" encoding="utf-8"?>
> >
> > <xsd:schema
> >
> >
> >
>
targetNamespace="http://schemas.interlacesystems.com/jaxbtest/JAXBTest.x
sd
> "
> >
> > elementFormDefault="qualified"
> >
> >
xmlns="http://schemas.interlacesystems.com/jaxbtest/JAXBTest.xsd"
> >
> > xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> >
> > xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
> >
> > xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
> >
> > jxb:version="2.0"
> >
> > jxb:extensionBindingPrefixes="xjc">
> >
> >
> >
> > <xsd:annotation>
> >
> > <xsd:appinfo>
> >
> > <jxb:globalBindings generateIsSetMethod="false"
> >
> > typesafeEnumBase="xsd:string"
> >
> > collectionType="java.util.ArrayList"
> >
> > choiceContentProperty="true"
> >
> > generateValueClass="false">
> >
> > <xjc:serializable/>
> >
> > </jxb:globalBindings>
> >
> > <jxb:schemaBindings>
> >
> > <jxb:package name="com.interlacesystems.jaxbtest"/>
> >
> > </jxb:schemaBindings>
> >
> > </xsd:appinfo>
> >
> > </xsd:annotation>
> >
> >
> >
> > <xsd:complexType name="MyObject">
> >
> > <xsd:annotation>
> >
> > <xsd:documentation xml:lang="en">A ModelObject is
a
> > toplevel object
> >
> > imported into the system via XML or the
Admin
> > UI</xsd:documentation>
> >
> > </xsd:annotation>
> >
> > <xsd:sequence>
> >
> > <xsd:element name="Description" type="xsd:string"
> > minOccurs="0"/>
> >
> > </xsd:sequence>
> >
> > <xsd:attribute name="id" type="xsd:long" use="optional"
> > default="-1"/>
> >
> > <xsd:attribute name="name" type="xsd:string"
> use="required"/>
> >
> > </xsd:complexType>
> >
> >
> >
> > <xsd:element name="SampleObject1" type="SampleObject1Type"/>
> >
> > <xsd:complexType name="SampleObject1Type">
> >
> > <xsd:complexContent>
> >
> > <xsd:extension base="MyObject">
> >
> > <xsd:attribute name="active"
type="xsd:boolean"
> > use="required"/>
> >
> > </xsd:extension>
> >
> > </xsd:complexContent>
> >
> > </xsd:complexType>
> >
> > </xsd:schema>
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > My code to test the unmarshalling is as follows...
> >
> >
> >
> > String SAMPLEOBJ1_XML =
> >
> > "<SampleObject1 " +
> >
> > "
> > xmlns=\"http://schemas.interlacesystems.com/jaxbtest/JAXBTest.xsd\""
+
> >
> > " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-
> instance\"" +
> >
> > " xsi:type=\"SampleObject1\"" +
> >
> > " name=\"sampleobject\"" +
> >
> > " active=\"true\">" +
> >
> > " <Description>This is a description</Description>" +
> >
> > "</SampleObject1>";
> >
> >
> >
> > JAXBContext jc =
> JAXBContext.newInstance("com.interlacesystems.jaxbtest");
> >
> > Unmarshaller unmarshaller = jc.createUnmarshaller();
> >
> > unmarshaller.setEventHandler(new DefaultValidationEventHandler());
> >
> > JAXBElement<?> obj = (JAXBElement<?>)unmarshaller.unmarshal(new
> > InputSource(new StringReader(SAMPLEOBJ1_XML)));
> >
> >
> >
> >
> >
> > Is there something I'm doing that's wrong?
> >
> >
> >
> > Anil
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net