Skip to main content

ERROR javax.xml.bind.UnmarshalException: Unexpected element - Need help

8 replies [Last post]
mjalleda
Offline
Joined: 2005-07-15

I am trying to execute my program to unmarshal the xml file but the following error occurs. I scanned thru the similar problems that were posted on Sun website but i didn't find the solution to solve the problem. Can you help me with this.

Here is Parser Code and error.

Thanks In advance,
Sudheer.

public static void main( String[] args ) {

System.out.println( "I am in the main method of TRI Parser" );

try {
// create a JAXBContext capable of handling classes
JAXBContext jc =
JAXBContext.newInstance( "us.net.exchangenetwork.sc._1._0:us.net.exchangenetwork.tri._1._0" );
// create an Unmarshaller
Unmarshaller u = jc.createUnmarshaller();

// unmarshal an instance document into a tree of Java content
// objects composed of classes from the us.net.exchangenetwork package.
System.out.println( "Preparing to display TRI Information : " );

TRI tri =
(TRI)u.unmarshal(new FileInputStream("TRIData.xml" ));

System.out.println( "display TRI Information : " + tri.getSubmission() );

} catch( JAXBException je ) {
je.printStackTrace();
} catch( IOException ioe ) {
ioe.printStackTrace();
}

C:\JDeveloper\jdk\bin\javaw.exe -client -classpath C:\TRINode\TRIParser\classes;C:\TRIJars\activation.jar;C:\TRIJars\ant-junit.jar;C:\TRIJars\ant-launcher.jar;C:\TRIJars\ant-nodeps.jar;C:\TRIJars\ant-trax.jar;C:\TRIJars\ant.jar;C:\TRIJars\cdx_document.jar;C:\TRIJars\classes12.jar;C:\TRIJars\commons-beanutils.jar;C:\TRIJars\commons-collections.jar;C:\TRIJars\commons-digester.jar;C:\TRIJars\commons-logging.jar;C:\TRIJars\dataflowclient.jar;C:\TRIJars\dom4j;C:\TRIJars\endorsed;C:\TRIJars\jaas.jar;C:\TRIJars\jax-qname.jar;C:\TRIJars\jaxb-api.jar;C:\TRIJars\jaxb-impl.jar;C:\TRIJars\jaxb-libs.jar;C:\TRIJars\jaxb-xjc.jar;C:\TRIJars\jaxp-api.jar;C:\TRIJars\jta-spec1_0_1.jar;C:\TRIJars\mail.jar;C:\TRIJars\namespace.jar;C:\TRIJars\relaxngDatatype.jar;C:\TRIJars\xsdlib.jar;C:\TRIJars\endorsed\dom.jar;C:\TRIJars\endorsed\sax.jar;C:\TRIJars\endorsed\xalan.jar;C:\TRIJars\endorsed\xercesImpl.jar Main
I am in the main method of TRI Parser Preparing to display TRI Information : DefaultValidationEventHandler: [ERROR]: Unexpected element {urn:us:net:exchangenetwork:TRI:1:0}:WaterSequenceNumber
Location: javax.xml.bind.UnmarshalException: Unexpected element {urn:us:net:exchangenetwork:TRI:1:0}:WaterSequenceNumber at us.net.exchangenetwork.sc._1._0.impl.runtime.SAXUnmarshallerHandlerImpl.handleEvent(SAXUnmarshallerHandlerImpl.java:577) at us.net.exchangenetwork.sc._1._0.impl.runtime.AbstractUnmarshallingEventHandlerImpl.reportError(AbstractUnmarshallingEventHandlerImpl.java:139) at us.net.exchangenetwork.sc._1._0.impl.runtime.AbstractUnmarshallingEventHandlerImpl.reportError(AbstractUnmarshallingEventHandlerImpl.java:136) at us.net.exchangenetwork.sc._1._0.impl.runtime.AbstractUnmarshallingEventHandlerImpl.unexpectedEnterElement(AbstractUnmarshallingEventHandlerImpl.java:147) at us.net.exchangenetwork.sc._1._0.impl.runtime.AbstractUnmarshallingEventHandlerImpl.enterElement(AbstractUnmarshallingEventHandlerImpl.java:60) at us.net.exchangenetwork.tri._1._0.impl.WaterStreamImpl$Unmarshaller.enterElement(WaterStreamImpl.java:182) at us.net.exchangenetwork.sc._1._0.impl.runtime.AbstractUnmarshallingEventHandlerImpl.revertToParentFromEnterElement(AbstractUnmarshallingEventHandlerImpl.java:329) at us.net.exchangenetwork.tri._1._0.impl.WaterStreamDataTypeImpl$Unmarshaller.enterElement(WaterStreamDataTypeImpl.java:217) at us.net.exchangenetwork.sc._1._0.impl.runtime.SAXUnmarshallerHandlerImpl.startElement(SAXUnmarshallerHandlerImpl.java:125) at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:485) at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:326) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1563) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:341) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:828) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:758) 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:1178) at us.net.exchangenetwork.sc._1._0.impl.runtime.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:140) at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:131) at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:178) at Main.main(Main.java:45) Process exited with exit code 0.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kohsuke
Offline
Joined: 2003-06-09

Hmm, it so far looks correct to me.
I suggest you try Unmarshaller.setValidating(true).

mjalleda
Offline
Joined: 2005-07-15

where do i need to do this setting. If i do will it solve the problem.

kohsuke
Offline
Joined: 2003-06-09

Before you invoke the Unmarshaller.unmarshal method, call its Unmarshaller.setValidating method to true.

This won't solve the problem, but it will probably give us more information to diagnose the problem.

mjalleda
Offline
Joined: 2005-07-15

I added the following in the code

JAXBContext jc =
JAXBContext.newInstance( "us.net.exchangenetwork.sc._1._0:us.net.exchangenetwork.tri._1._0" );
// create an Unmarshaller
Unmarshaller u = jc.createUnmarshaller();
u.setValidating(true);
// unmarshal an instance document into a tree of Java content
// objects composed of classes from the us.net.exchangenetwork package.
System.out.println( "Preparing to display TRI Information : " );
TRI tri =
(TRI)u.unmarshal(new FileInputStream("TRIData.xml" ));

Here is the error log

DefaultValidationEventHandler: [ERROR]: tag name "TRI:WaterSequenceNumber" is not allowed. Possible tag names are: ,
Location:

com.sun.msv.verifier.ValidityViolation: tag name "TRI:WaterSequenceNumber" is not allowed. Possible tag names are: ,

at com.sun.msv.verifier.Verifier.onError(Verifier.java:367)

at com.sun.msv.verifier.Verifier.onError(Verifier.java:363)

at com.sun.msv.verifier.Verifier.startElement(Verifier.java:203)

at com.sun.msv.verifier.VerifierFilter.startElement(VerifierFilter.java:97)

at org.iso_relax.verifier.impl.ForkContentHandler.startElement(ForkContentHandler.java:75)

at us.net.exchangenetwork.sc._1._0.impl.runtime.ValidatingUnmarshaller.startElement(ValidatingUnmarshaller.java:101)

at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:485)

at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:326)

at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1563)

at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:341)

at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:828)

at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:758)

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:1178)

at us.net.exchangenetwork.sc._1._0.impl.runtime.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:140)

at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:131)

at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:178)

at Main.main(Main.java:45)

--------------- linked to ------------------

javax.xml.bind.UnmarshalException: tag name "TRI:WaterSequenceNumber" is not allowed. Possible tag names are: ,
- with linked exception:
[com.sun.msv.verifier.ValidityViolation: tag name "TRI:WaterSequenceNumber" is not allowed. Possible tag names are: ,]

at us.net.exchangenetwork.sc._1._0.impl.runtime.SAXUnmarshallerHandlerImpl.handleEvent(SAXUnmarshallerHandlerImpl.java:577)

at us.net.exchangenetwork.sc._1._0.impl.runtime.ErrorHandlerAdaptor.propagateEvent(ErrorHandlerAdaptor.java:81)

at us.net.exchangenetwork.sc._1._0.impl.runtime.ErrorHandlerAdaptor.error(ErrorHandlerAdaptor.java:45)

at com.sun.msv.verifier.Verifier.onError(Verifier.java:371)

at com.sun.msv.verifier.Verifier.onError(Verifier.java:363)

at com.sun.msv.verifier.Verifier.startElement(Verifier.java:203)

at com.sun.msv.verifier.VerifierFilter.startElement(VerifierFilter.java:97)

at org.iso_relax.verifier.impl.ForkContentHandler.startElement(ForkContentHandler.java:75)

at us.net.exchangenetwork.sc._1._0.impl.runtime.ValidatingUnmarshaller.startElement(ValidatingUnmarshaller.java:101)

at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:485)

at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:326)

at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1563)

at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:341)

at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:828)

at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:758)

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:1178)

at us.net.exchangenetwork.sc._1._0.impl.runtime.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:140)

at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:131)

at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:178)

at Main.main(Main.java:45)

Process exited with exit code 0.

kohsuke
Offline
Joined: 2003-06-09

So that's probably what it is. The document you are trying to marshal is invalid wrt the schema --- it got where it should have or .

mjalleda
Offline
Joined: 2005-07-15

Here is the schema containing water sequence number.





Schema Name : TRI_WaterStream_v1.0.xsd
Current Version Available At :
Description : The names of the streams, rivers, lakes, or other water bodies to which the chemical is discharged.
Application :
Developed by : Environmental Protection Agency, Windsor Solutions, Inc.
Point of Contact : William Geake




The names of the streams, rivers, lakes, or other water bodies to which the chemical is discharged and percent of which comes from stormwater














Sequence in which a release to water is reported on a Form R submission.




The name of the stream, river, lake, or other water body to which the chemical is discharged.




The amount of the release, by weight percent, to water bodies, that came from stormwater runoff.




Indicates that 'NA' (Not Applicable) was entered on Form R for the percent of a release that came from stormwater runoff.


kohsuke
Offline
Joined: 2003-06-09

For JAXB 1.0.x issues, consider using users@jaxb.dev.java.net (you need to subscribe from http://jaxb.dev.java.net/)

I strongly suspect that your schema is not what you think it is. Please post the schema that contains the definition of {urn:us:net:exchangenetwork:TRI:1:0}:WaterSequenceNumber
and the portion of the instance document that matches this.

Also turn on Unmarshaller.setValidating(true). This usually produces a much better error message.

mjalleda
Offline
Joined: 2005-07-15

These two are the packages in my project where the jaxb.properties file exists. There are 41 schemas in total and when used jaxb it created 1147 classes in two different packages given below.

us.net.exchangenetwork.sc._1._0
us.net.exchangenetwork.tri._1._0

The root schema is given below.










Schema Name : TRI_TRI_v1.0.xsd
Current Version Available At :
Description : This is the root schema for Toxic Release Inventory reporting data
Aplication :
Developed by : Environmental Protection Agency, Windsor Solutions, Inc.
Point of Contact : William Geake










A container for one or more TRI Reports for a given facility











A number used to uniquely identify a TRI submission, which contains data for one facility and one or more chemicals