atom feed3 messages in net.java.dev.jwsdp.usersRe: Coalescing events in StAX
FromSent OnAttachments
Neeraj BajajJul 19, 2005 10:38 pm 
Kirill GrouchnikovJul 19, 2005 11:06 pm 
Neeraj BajajJul 19, 2005 11:30 pm 
Subject:Re: Coalescing events in StAX
From:Neeraj Bajaj (Neer@Sun.COM)
Date:Jul 19, 2005 11:30:53 pm
List:net.java.dev.jwsdp.users

Its a directive. Yes, All StAX implementations should behave this way.

If you have entity references with in your content, read further. It's not clear what should be the behavior when ":is_coalesce" property is set to true and "entity_references" is set to false. SJSXP gives preference to coalesce and coalesces the character data. Check the SJSXP release notes for mote detail on this issue.

- Neeraj

Kirill Grouchnikov wrote:

Neeraj,

If i set this property to "true", is it a hint or a directive? Do all StAX implementations (BEA, Sun, WebLogic) behave the same way? If i have a lot of CHARACTERS events, will they all be coalesced?

Thanks Kirill

--- Neeraj Bajaj <Neer@Sun.COM> wrote:

Generally I cc to use@jaxp.dev.java.net & use@jaxp.dev.java.net mailing list.

Kirill,

You might want to check StAX "javax.xml.stream.isCoalescing" property, where StAX parser will coalesce the adjacent character data for you.

- Neeraj

[1]

https://stax-utils.dev.java.net/nonav/javadoc/api/javax/xml/stream/XMLInputFactory.html

Kirill Grouchnikov wrote:

Hi, Neeraj

I forgot if there's a mailing list for sjsxp, so feel

free

to CC your reply to it.

A question on coalescing events:

Suppose i have the following loop

XMLEventReader eventReader = xmlif.createXMLEventReader(reader); while (eventReader.hasNext()) { XMLEvent currEvent = eventReader.nextEvent(); // do something with the event } }

In this case, i can have multiple CHARACTERS events in a row. I would like to be able to do one of the following: 1. Specify to the parser that i want a single CHARACTERS event. 2. Be able to collect all CHARACTERS events until a non-CHARACTER event comes and then continue.

In the later case, i do not see any function that allows

to

"push back" an event to the reader. I have come up with

the

following (quite ugly) code:

XMLEventReader eventReader = xmlif.createXMLEventReader(reader); XMLEvent currEvent = null; boolean toTakeNextEvent = true; while (true) { if (toTakeNextEvent) { if (!eventReader.hasNext()) break; currEvent = eventReader.nextEvent(); } toTakeNextEvent = true;

switch (currEvent.getEventType()) { ... case XMLEvent.CHARACTERS: // start coalescing CHARACTERS events toTakeNextEvent = false; Characters chEvent = (Characters) currEvent; LinkedList<Characters> charEvents = new LinkedList<Characters>(); charEvents.addFirst(chEvent); while (true) { currEvent = eventReader.nextEvent(); if (currEvent.getEventType() != XMLEvent.CHARACTERS) break; charEvents.addLast((Characters) currEvent); } if (!chEvent.isWhiteSpace()) { result.addElementInfo(this .getCharactersInfo(charEvents)); } // do something with charEvents list break; } }

Here, i start pulling the events once i get CHARACTERS

and

until i get non-CHARACTER event and use boolean variable

to

decide whether to pull next event from the reader or

reuse

the previously pulled event.

Is there more elegant way to do this?

And in case you wonder, i do need the coalescing because

of

the Locator discrepancies between consecutive CHARACTERS events.

Thanks

---------------------------------------------------------------------

To unsubscribe, e-mail: user@jwsdp.dev.java.net For additional commands, e-mail: user@jwsdp.dev.java.net