users@jaxb.java.net

RE: SAXParseException: unexpected root element

From: Steve Wingard <Steve.Wingard_at_digeo.com>
Date: Thu, 16 Jan 2003 07:49:51 -0800

I have seen the same error in the past. In my case, I think it was due to the fact that I was attempting to compile multiple schemas into a single package and output directory.
 
Each time you invoke the "xjc" compiler on a different schema file, it creates a number of files for that schema including some that have "standardized" names
 
    bgm.ser
    jaxb.properties
    ObjectFactory.*
 
But the contents of the 'bgm.ser' and Object Factory files are going to be specific to a particular schema. So when I compiled several schema files into the same output directory, I wound up overwriting the "bgm.ser" data that was created for earlier schemas.
 
If my test program had been written to use the LAST schema I compiled, everything would work. But I was trying to use one of the 'earlier' schemas I'd compiled, so the unmarshaller got confused because the XML it was examining did not match the generated bgm.ser file.
 
What I wound up doing was putting each of my schemas into a different package to avoid namespace collisions among the different ObjectFactories. That caused "xjc" to put the output for each schema into its own directory, and my problem was solved.
 
I don't know if that will help you out or not. Good luck!

 
 
-----Original Message-----
From: Brad Siegfreid [mailto:brad_at_iridiumdesign.com]
Sent: Wednesday, January 15, 2003 6:04 PM
To: JAXB-INTEREST_at_JAVA.SUN.COM
Subject: SAXParseException: unexpected root element



Hello all.

This is my first post so please bear with me if this question is redundant. I've searched the developer forums at java.sun.com and found others with a similar issue but no answers. After a week of banging my head I'm turning to you.

I've posted the files I'm working with at:

http://www.iridiumdesign.com/xs/preferences.xsd
http://www.iridiumdesign.com/test/preferences-test.xml

Using the dom.Writer app from the Xerces 2.2.1 sample files I've worked out (at least I think so) any issues with my schema and xml files. The file seems to validate from the command line.

However, when I load the files into my web server and start Resin its showing the following error. I've loaded the latest versions of Xerces and JAXP and I'm running on Java 1.3.1 on Mac OS X 10.2.3.

org.xml.sax.SAXParseException: unexpected root element pref:preferences
at com.sun.xml.bind.unmarshaller.SAXUnmarshallerHandlerImpl.startElement(SAXUnmarshallerHandlerImpl.java:81)
at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.xml.bind.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:139)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:129)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:166)
at com.iridiumdesign.ControlServlet.init(ControlServlet.java:85)
at com.caucho.server.http.Application.createServlet(Application.java:3103)
at com.caucho.server.http.Application.loadServlet(Application.java:3054)
at com.caucho.server.http.Application.initServlets(Application.java:1914)
at com.caucho.server.http.Application.init(Application.java:1827)
at com.caucho.server.http.VirtualHost.init(VirtualHost.java:720)
at com.caucho.server.http.ServletServer.initHosts(ServletServer.java:853)
at com.caucho.server.http.ServletServer.initInternal(ServletServer.java:698)
at com.caucho.server.http.ServletServer.init(ServletServer.java:509)
at com.caucho.server.http.ResinServer.init(ResinServer.java:377)
at com.caucho.server.http.ResinServer.main(ResinServer.java:1137)
at com.caucho.server.http.HttpServer.main(HttpServer.java:103)
--------------- linked to ------------------
javax.xml.bind.UnmarshalException
- with linked exception:
[org.xml.sax.SAXParseException: unexpected root element pref:preferences]
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(AbstractUnmarshallerImpl.java:284)
at com.sun.xml.bind.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:143)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:129)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:166)
at com.iridiumdesign.ControlServlet.init(ControlServlet.java:85)
at com.caucho.server.http.Application.createServlet(Application.java:3103)
at com.caucho.server.http.Application.loadServlet(Application.java:3054)
at com.caucho.server.http.Application.initServlets(Application.java:1914)
at com.caucho.server.http.Application.init(Application.java:1827)
at com.caucho.server.http.VirtualHost.init(VirtualHost.java:720)
at com.caucho.server.http.ServletServer.initHosts(ServletServer.java:853)
at com.caucho.server.http.ServletServer.initInternal(ServletServer.java:698)
at com.caucho.server.http.ServletServer.init(ServletServer.java:509)
at com.caucho.server.http.ResinServer.init(ResinServer.java:377)
at com.caucho.server.http.ResinServer.main(ResinServer.java:1137)
at com.caucho.server.http.HttpServer.main(HttpServer.java:103)