Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

SAXParseException: Parsing large XML files with JAXB and StAX

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Ranch Hand
Posts: 734
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
That which doesn't kill us makes us stronger. I think a piece of pie wouldn't kill me. Tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic