*
The moose likes XML and Related Technologies and the fly likes javax.xml.bind.UnmarshalException: unexpected element (uri: Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"AirAvailabilityRS")" Watch "javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"AirAvailabilityRS")" New topic
Author

javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"AirAvailabilityRS")

Jennifer Moran
Ranch Hand

Joined: Oct 21, 2002
Posts: 60
Here is my scaled down XSD


Here is XML


Here is the unmarshalling code


I get this error

javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"AirAvailabilityRS"). Expected elements are <{http://farelogix.com/flx/tc}agent>,<{http://farelogix.com/flx/tc}iden>,<{http://farelogix.com/flx/tc}provider>,<{http://farelogix.com/flx/tc}script>,<{http://farelogix.com/flx/tc}tc>

Which is weird because the expected elements are for a different schema that is used in the soap header


Any help would be appreciated...

Thanks!
Suresh Sudineni
Greenhorn

Joined: Jul 18, 2008
Posts: 3
i am also facing sme issue.

could anyone please provide the solution?
hemanth kollah
Greenhorn

Joined: Apr 11, 2012
Posts: 7
Did you guys fix the above issue? I am having the same problem.
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1012
    
    5

Try this code instead:
hemanth kollah
Greenhorn

Joined: Apr 11, 2012
Posts: 7
Thank you for the reply James, I have an unmarshal like below

private Setup unmarshal(DataHandler DataHandler, String jaxbPackageInstance)
throws Exception
{
JAXBContext jaxbContext = JAXBContext.newInstance(jaxbPackageInstance);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
return (Setup)unmarshaller.unmarshal(DataHandler.getDataSource().getInputStream());

}

When I execute this from my project it throws me an error message as below.

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)

Please letme know if I am missing something.

James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1012
    
    5

Instead of:



Try:

hemanth kollah
Greenhorn

Joined: Apr 11, 2012
Posts: 7
I changed my code with the proposed changes and now I get the below error message

javax.xml.bind.JAXBException: com.ec.copec.lw.configuration.Setup is not known to this context
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getBeanInfo(JAXBContextImpl.java:587)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.getBeanInfo(UnmarshallerImpl.java:531)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:190)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:241)


I checked that Setup.java is already present in the Location where I need.
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1012
    
    5

hemanth

Instead of:



Try:

hemanth kollah
Greenhorn

Joined: Apr 11, 2012
Posts: 7
Thank you Much James, I have rebuild the Setup.java and ObjectFactory.java files using the XJC utility and replaced my project files with the new version of the files. I used your suggestion and that resolved the unmarshalleing error.

JAXBElement<Setup> root = unmarshaller.unmarshal(new StreamSource(DataHandler.getDataSource().getInputStream()), Setup.class);
return root.getValue();
 
 
subject: javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"AirAvailabilityRS")
 
Similar Threads
Can't generate java classes from WSDL file
Exception while UNmarshalling
xml validation with the java 5
how to implement ws-security in soap request header
Web Service message level Encryption Decryption through public and private key