Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SAXParseException: Parsing large XML files with JAXB and StAX

 
Sverre Moe
Ranch Hand
Posts: 110
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 650
3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 110
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic