• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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.
 
She's brilliant. She can see what can be and is not limited to what is. And she knows this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic