*
The moose likes XML and Related Technologies and the fly likes Lookahead possible for XML parsing in stream/event style 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 "Lookahead possible for XML parsing in stream/event style" Watch "Lookahead possible for XML parsing in stream/event style" New topic
Author

Lookahead possible for XML parsing in stream/event style

manuel aldana
Ranch Hand

Joined: Dec 29, 2005
Posts: 308
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.


aldana software engineering blog & .more
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
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

Joined: Dec 29, 2005
Posts: 308
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
Bartender

Joined: Oct 14, 2005
Posts: 18669
    
    8

Sounds like a job for a SAX filter.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Lookahead possible for XML parsing in stream/event style