Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Lookahead possible for XML parsing in stream/event style

 
manuel aldana
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

because I got big xml-files I am using streaming/event style to parse xml entries and let them later transform to jaxb-objects.

a simplified xml example:


here i only want to receive an event for users who are aktive="true".



for that a lookahead would be necessary, but is such a lookahead possible with xml parsing in stream/event style (when getting a start-element-event it does not know about children elements, which is against the "nature" of streaming)?

thanks.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The simplest thing to do would be to start storing data in a new object when you hit a new user but discard it if active.equals("false"). If your custom object implemented a clear() method this would not involve excess object creation.

Exactly why do you feel JAXB is what you need? (just curious)

Bill
 
manuel aldana
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, that is what i am exactly doing right now (loading complete jaxb object and the query java style and filter it afterward)

but i was just interested whether such a lookahead is possible, because it happens quite often that you need some information of xml-children nodes when working on the events and don't want to unnecessarily parse to jaxb objects.

the jaxb-stream style works quite well on my machine. having a monster export file (~900MB) and iterating ~200K items takes only 90 seconds.

reason i used jaxb:
-quite big and complicated schema (couldn't bother to fiddle around with xpath or other queries)
-i need to traverse a lot of data from one xml entry inside java
-xjc to generate jaxb-classes out from xsd was quite smooth
 
Paul Clapham
Sheriff
Posts: 21298
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like a job for a SAX filter.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic