aspose file tools*
The moose likes XML and Related Technologies and the fly likes SAXParseException: Parsing large XML files with JAXB and StAX Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "SAXParseException: Parsing large XML files with JAXB and StAX" Watch "SAXParseException: Parsing large XML files with JAXB and StAX" New topic
Author

SAXParseException: Parsing large XML files with JAXB and StAX

Sverre Moe
Ranch Hand

Joined: Jul 10, 2007
Posts: 110
I have build my own XML schema for invoice events and are using JAXB2 to parse an XML document based upon this XML schema.

The following piece of code works fine, but does not handle very large files:


Then I tried using StAX with JAXB in order to stream read the XML file.

Soluton1:


Solution2:


Both solutions with StAX gives me the following error:

javax.xml.bind.UnmarshalException
- with linked exception:
[org.xml.sax.SAXParseException; lineNumber: 3; columnNumber: 15; cvc-elt.1: Cannot find the declaration of element 'invoiceEvent'.]
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(UnmarshallerImpl.java:419)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:356)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:326)
at Invoice.main(Invoice.java:90)
Caused by: org.xml.sax.SAXParseException; lineNumber: 3; columnNumber: 15; cvc-elt.1: Cannot find the declaration of element 'invoiceEvent'.


My XML Schema file:


The first few lines of my XML file:
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 535
    
    3
Haven't digested the message at all. But a quick browse over see this.
xsi:noNamespaceSchemaLocation="http://myURL.com/schema/invoice http://myURL.com/schema/invoice/invoice-invoiceevent-1.0.xsd"

It is an incorrect xsi:noNamespaceSchemaLocation attribute. It should look more like this.
xsi:noNamespaceSchemaLocation="http://myURL.com/schema/invoice/invoice-invoiceevent-1.0.xsd"
Sverre Moe
Ranch Hand

Joined: Jul 10, 2007
Posts: 110
g tsuji wrote:Haven't digested the message at all. But a quick browse over see this.
xsi:noNamespaceSchemaLocation="http://myURL.com/schema/invoice http://myURL.com/schema/invoice/invoice-invoiceevent-1.0.xsd"

It is an incorrect xsi:noNamespaceSchemaLocation attribute. It should look more like this.
xsi:noNamespaceSchemaLocation="http://myURL.com/schema/invoice/invoice-invoiceevent-1.0.xsd"


I have updated my XML file accordingly.

Found the problem: When using StAX I needed to make a change to my XML Schema.

Then I could use my XML Schema with both JAXB collecting the entire InvoiceEvents, and StAX and streaming single InvoiceEvent.

Though, solution1 and 2 worked I would like to know whats the difference in using XMLEventReader and XMLStreamReader.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SAXParseException: Parsing large XML files with JAXB and StAX