users@jaxb.java.net

Re: Unmarshal a sax stream in parts

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Tue, 22 Mar 2011 12:12:14 +0100

A hack: You might use an Unmarshaller.Listener where afterUnmarshal would
give you
the next MessagePart object as soon as it is complete. You process it, and
you "destroy" as much of it as you can, calling its setters with null
arguments,
or clear its lists (whch don't have setters).

-W

On 22 March 2011 11:37, Nick Stolwijk <nick.stolwijk_at_gmail.com> wrote:

> Hi,
>
> I was wondering if it was possible to unmarshal a sax stream into
> objects one by one. We have a large xml message and we want to process
> each part as a Java object.
>
> i.e.
>
> <message>
> <message-part <--! the message part --> />
> <message-part <--! the message part --> />
> <message>
>
> And we want each message-part as a MessagePart object but not at the same
> time.
>
> So,
> (Pseudocode)
> while (saxStream ! empty) {
> MessagePart part = unmarshaller.unmarshall(?);
> process(part);
> }
>
> Can someone tell me if this is possible and point me in the right
> direction?
>
> With regards,
>
> Nick Stolwijk
> ~Senior Java Developer~
>
> iPROFS
> Wagenweg 208
> 2012 NM Haarlem
> T +31 23 547 6369
> F +31 23 547 6370
> I www.iprofs.nl
>