aspose file tools*
The moose likes XML and Related Technologies and the fly likes JAXB 2.1 Unmarshaller error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "JAXB 2.1 Unmarshaller error" Watch "JAXB 2.1 Unmarshaller error" New topic
Author

JAXB 2.1 Unmarshaller error

hemanth kollah
Greenhorn

Joined: Apr 11, 2012
Posts: 7
Hello I am trying to run a program and I get this error message at run time. Please suggest me a solution to get around this error message?

javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"setup"). Expected elements are (none)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:609)
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:244)
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:239)
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement(Loader.java:116)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext$DefaultRootLoader.childElement(UnmarshallingContext.java:1015)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:452)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:433)
at com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:137)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:533)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:330)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(XMLNSDocumentScannerImpl.java:779)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1794)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:368)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:834)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1242)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:211)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:184)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:137)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:184)
at com.ec.copec.lw.configuration.ConfigurationHandler.unmarshal(ConfigurationHandler.java:65)
at com.ec.copec.lw.configuration.ConfigurationHandler.getConfigurationWithName(ConfigurationHandler.java:29)
at com.ec.copec.lw.configuration.TestConfiguration.main(TestConfiguration.java:18)
BUILD SUCCESSFUL (total time: 0 seconds)
Vipul Bhara
Greenhorn

Joined: Aug 12, 2009
Posts: 22

I have same question.... I am getting exact error message..
hemanth kollah
Greenhorn

Joined: Apr 11, 2012
Posts: 7
This was resolved in http://www.coderanch.com/t/532053/XML/javax-xml-bind-UnmarshalException-unexpected .

Please use XJC commant line utility to create java files from your xsd.
Vipul Bhara
Greenhorn

Joined: Aug 12, 2009
Posts: 22

I generated it using XJC only.... I am still getting this exception
hemanth kollah
Greenhorn

Joined: Apr 11, 2012
Posts: 7
After generating the code from XJC, I changed my Unmarshal code as below.

JAXBContext jaxbContext = JAXBContext.newInstance(jaxbPackageInstance);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
// return (Setup)unmarshaller.unmarshal(dataHandler.getDataSource().getInputStream()); /* Original Code */
JAXBElement<Setup> root = unmarshaller.unmarshal(new StreamSource(dataHandler.getDataSource().getInputStream()), Setup.class);
return root.getValue();

Instead of return (Setup)unmarshaller.unmarshal(dataHandler.getDataSource().getInputStream()); I added the new 2 lines to resolve the unmarshaller error.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JAXB 2.1 Unmarshaller error