f



Are there any tools which generates Java code to reading XML files?

Hello,

I use SAXParserFactory to read data from XML files.

Lets see some sample XML:

<cyclogram>
    <number>1</number>
    <step>
       <number>11</number>
    </step>
</cyclogram>

<cyclogram>
    <number>1</number>
    <step>
       <number>11</number>
    </step>
</cyclogram>

Since "number" is both in "cyclogram" and "step" we
need to pursue if we are actually in "cyclogram" or in "step",
to decide if "number" is connected to "cyclogram" or to
"step".

I wonder, if there are tools which could automatically
generate Java code for purpose of reading XML files.
For example, user of such tool could define structure
of XML file with use of some GUI (e.g. tree structure
graphicaly represented). After that user could press some
button and see Java code...
I hope you understand what I mean.

Regards,
  Robbo 


0
Robbo
3/23/2010 11:14:27 PM
comp.lang.java.programmer 52640 articles. 0 followers. Post Follow

21 Replies
380 Views

Similar Articles

[PageSpeed] 52

On 23-03-2010 19:14, Robbo wrote:
> I use SAXParserFactory to read data from XML files.
>
> Lets see some sample XML:
>
> <cyclogram>
>      <number>1</number>
>      <step>
>         <number>11</number>
>      </step>
> </cyclogram>
>
> <cyclogram>
>      <number>1</number>
>      <step>
>         <number>11</number>
>      </step>
> </cyclogram>
>
> Since "number" is both in "cyclogram" and "step" we
> need to pursue if we are actually in "cyclogram" or in "step",
> to decide if "number" is connected to "cyclogram" or to
> "step".
>
> I wonder, if there are tools which could automatically
> generate Java code for purpose of reading XML files.
> For example, user of such tool could define structure
> of XML file with use of some GUI (e.g. tree structure
> graphicaly represented). After that user could press some
> button and see Java code...
> I hope you understand what I mean.

Parsing that with SAX requires you to keep context.

If you have a schema and can generate Java classes via
XJC (JAXB), then that would be a lot easier.

Arne
0
ISO
3/24/2010 12:17:53 AM
On 23/03/2010 23:14, Robbo wrote:
> Hello,
>
> I use SAXParserFactory to read data from XML files.
>
> Lets see some sample XML:
>
> <cyclogram>
>      <number>1</number>
>      <step>
>         <number>11</number>
>      </step>
> </cyclogram>
>
> <cyclogram>
>      <number>1</number>
>      <step>
>         <number>11</number>
>      </step>
> </cyclogram>
>
> Since "number" is both in "cyclogram" and "step" we
> need to pursue if we are actually in "cyclogram" or in "step",
> to decide if "number" is connected to "cyclogram" or to
> "step".

DOM and XPath seem the obvious tools for this.

http://www.ibm.com/developerworks/library/x-javaxpathapi.html

-- 
RGB
0
RedGrittyBrick
3/24/2010 10:18:09 AM
I would be glad, if you could tell me, what is the reason
for existing of SAXParserFactory, since there are better
(faster in coding) solutions? Somebody uses SAXParserFactory
and if yes, for what purposes?
I use SAXParserFactory and it is quite much work to
do with bunch of  "if" instructions, boolean variables...

Robbo 


0
Robbo
3/24/2010 4:12:26 PM
On Wed, 24 Mar 2010 00:14:27 +0100, "Robbo" <nie.mam@yle.com> wrote,
quoted or indirectly quoted someone who said :

>
>I wonder, if there are tools which could automatically
>generate Java code for purpose of reading XML files.

That is what JAXB does, which I find the most convenient way to read
XML files.  see http://mindprod.com/jgloss/jaxb.html

The are all kinds of ways to read XML. See
http://mindprod.com/jgloss/xml.html
and follow the links.

-- 
Roedy Green Canadian Mind Products
http://mindprod.com

Responsible Development is the style of development I aspire to now. It can be summarized by answering the question, �How would I develop if it were my money?� I�m amazed how many theoretical arguments evaporate when faced with this question. 
~ Kent Beck (born: 1961 age: 49) , evangelist for extreme programming.
0
Roedy
3/24/2010 4:52:28 PM
Robbo wrote:
> I would be glad, if you could tell me, what is the reason
> for existing of SAXParserFactory, since there are better
> (faster in coding) solutions? Somebody uses SAXParserFactory
> and if yes, for what purposes?

I use it:
- Whenever an event-driven approach to read my XML is easier (admittedly 
rare.)
- Whenever my XML files are big enough that I don't want to load them 
into a DOM object. Being event-driven, SAX does not load the whole 
document in memory.
- As a base for building some ad-hoc solutions. This overlaps a lot with 
my previous reason. I imagine most solutions are based off SAX builders.

> I use SAXParserFactory and it is quite much work to
> do with bunch of  "if" instructions, boolean variables...

Yes. I usually need to wrap one or more simplification layers around it. 
Usually the layers above the first one are specialized to the XML I'm 
reading.

Rather often when you deal with XML, there are more specialized APIs 
that will address your needs better. Notably JAXB.

However, nothing is perfect for every use cases, and the game is to find 
the right tool for the given problem. Here, it looks like you'd love 
JAXB. If it somehow seems too complicated or overkill, you'd at least 
save time with a DOM approach.

(Confession: I don't have a clue about StAX. It might be good.)

--
Mayeul
0
Mayeul
3/24/2010 5:04:19 PM
Arne Vajh�j wrote:
> On 23-03-2010 19:14, Robbo wrote:
>> I use SAXParserFactory to read data from XML files.
>>
>> Lets see some sample XML:
>>
>> <cyclogram>
>>      <number>1</number>
>>      <step>
>>         <number>11</number>
>>      </step>
>> </cyclogram>
>>
>> <cyclogram>
>>      <number>1</number>
>>      <step>
>>         <number>11</number>
>>      </step>
>> </cyclogram>
>>
>> Since "number" is both in "cyclogram" and "step" we
>> need to pursue if we are actually in "cyclogram" or in "step",
>> to decide if "number" is connected to "cyclogram" or to
>> "step".
>>
>> I wonder, if there are tools which could automatically
>> generate Java code for purpose of reading XML files.
>> For example, user of such tool could define structure
>> of XML file with use of some GUI (e.g. tree structure
>> graphicaly represented). After that user could press some
>> button and see Java code...
>> I hope you understand what I mean.
> 
> Parsing that with SAX requires you to keep context.


Yes - normally a simple tag stack is sufficient (push on start,
pop on end).

   BugBear
0
bugbear
3/24/2010 5:09:49 PM
On Wed, 24 Mar 2010 17:12:26 +0100, "Robbo" <nie.mam@yle.com> wrote,
quoted or indirectly quoted someone who said :

>I would be glad, if you could tell me, what is the reason
>for existing of SAXParserFactory, since there are better
>(faster in coding) solutions? 

Even if it were utterly useless compared with the alternatives, it
would still have to exist to support legacy apps.

An essay is in order to explain the advantages and disadvantages of
the various XML tools, and the circumstances under which you would
best choose each one.

If anyone wants to toss some ideas into the ring, I will compile them
for the entry at http://mindprod.com/jgloss/xml.html
-- 
Roedy Green Canadian Mind Products
http://mindprod.com

Responsible Development is the style of development I aspire to now. It can be summarized by answering the question, �How would I develop if it were my money?� I�m amazed how many theoretical arguments evaporate when faced with this question. 
~ Kent Beck (born: 1961 age: 49) , evangelist for extreme programming.
0
Roedy
3/24/2010 8:45:14 PM
Robbo quoted or indirectly quoted someone who said :
>> I would be glad, if you could tell me, what is the reason
>> for existing of SAXParserFactory, since there are better
>> (faster in coding) solutions?
>

'SAXParserFactory' exists for the purpose of enabling "applications to
configure and obtain a SAX based parser to parse XML documents", as
you would know if you read its Javadocs.

Roedy Green wrote:
> Even if it were utterly useless compared with the alternatives, it
> would still have to exist to support legacy apps.
>

And of course, it's far from useless.

> An essay is in order to explain the advantages and disadvantages of
> the various XML tools, and the circumstances under which you would
> best choose each one.
>
> If anyone wants to toss some ideas into the ring, I will compile them
> for the entry athttp://mindprod.com/jgloss/xml.html
>

SAX parsing is superior to DOM parsing (by which I include all the
different DOM-based approaches) when you want to represent the
information from the XML document in some structure different from the
document structure or need really, really fast parsing.  It's much,
much faster than DOM-based parsing because it pulls in the information
directly into your object model without the intermediate DOM
structure, in a single pass through the document, using much less
memory overall.  It is good when you have a specific target object
structure for the information, and don't need or want XPath/XQuery or
equivalent means of access to the document structure.  XPath and
XQuery can really slow an application down, especially as document
structures get large (approaching 1 GB).

As for DOM-based approaches being faster to code, I don't think that's
necessarily true.  A project I was on last year had its development
slowed down horribly by its attempt to use DOM parsing.  The documents
were quite large, and the geometric increase in processing time caused
by that was forcing all kinds of epicycles to try to improve things.
They'd have had a solution much faster if they'd used SAX (or StAX)
parsing.

--
Lew
0
Lew
3/24/2010 9:35:39 PM
On 24-03-2010 12:12, Robbo wrote:
> I would be glad, if you could tell me, what is the reason
> for existing of SAXParserFactory, since there are better
> (faster in coding) solutions? Somebody uses SAXParserFactory
> and if yes, for what purposes?
> I use SAXParserFactory and it is quite much work to
> do with bunch of  "if" instructions, boolean variables...

SAX is great for parsing huge XML files where you
only need some of the information.

Arne
0
ISO
3/24/2010 11:16:48 PM
On 24-03-2010 13:09, bugbear wrote:
> Arne Vajh�j wrote:
>> On 23-03-2010 19:14, Robbo wrote:
>>> I use SAXParserFactory to read data from XML files.
>>>
>>> Lets see some sample XML:
>>>
>>> <cyclogram>
>>> <number>1</number>
>>> <step>
>>> <number>11</number>
>>> </step>
>>> </cyclogram>
>>>
>>> <cyclogram>
>>> <number>1</number>
>>> <step>
>>> <number>11</number>
>>> </step>
>>> </cyclogram>
>>>
>>> Since "number" is both in "cyclogram" and "step" we
>>> need to pursue if we are actually in "cyclogram" or in "step",
>>> to decide if "number" is connected to "cyclogram" or to
>>> "step".
>>>
>>> I wonder, if there are tools which could automatically
>>> generate Java code for purpose of reading XML files.
>>> For example, user of such tool could define structure
>>> of XML file with use of some GUI (e.g. tree structure
>>> graphicaly represented). After that user could press some
>>> button and see Java code...
>>> I hope you understand what I mean.
>>
>> Parsing that with SAX requires you to keep context.
>
> Yes - normally a simple tag stack is sufficient (push on start,
> pop on end).

But you still need a bunch of if statements.

And the final code can easily become a bit messy.

I would prefer alternatives if they exists and are
usable in the context.

Arne
0
ISO
3/24/2010 11:17:59 PM
Arne Vajhøj wrote:
> But you still need a bunch of if statements [for SAX parsing].

I've written a handful of SAX-parser based applications, starting with my 
first paid Java gig eleven years ago.  There really weren't many 'if' 
statements in them; mostly I just instantiated an object based on the tag 
being processed, using a Map to look up the appropriate handler.  In this it 
was similar to MVC code for servlets where you look up the handler based on a 
request parameter.

> And the final code can easily become a bit messy.

That's on the programmer, not the library.

> I would prefer alternatives if they exists and are
> usable in the context.

SAX is /non pareil/ for the areas where it shines.  Back in 1999, using Java 
1.2 and then-current LAN tech (no gigabit or 100Mb/s LANs then) and the 
relatively low-memory machines of the day we could process on the order of a 
million hefty documents into or out of a database in about four hours using 
SAX.  We were limited pretty much by transfer speeds not CPU because of the 
efficiency of SAX parsing.

And there weren't a lot of 'if' statements involved, no more so than any other 
app I've worked on.

-- 
Lew
0
Lew
3/25/2010 12:10:02 AM
Robbo wrote:
>> I would be glad, if you could tell me, what is the reason
>> for existing of SAXParserFactory, since there are better
>> (faster in coding) solutions? Somebody uses SAXParserFactory
>> and if yes, for what purposes?
>> I use SAXParserFactory and it is quite much work to
>> do with bunch of  "if" instructions, boolean variables...

Arne Vajhøj wrote:
> SAX is great for parsing huge XML files where you
> only need some of the information.

Or all the information but not in the document's structure, or you have memory 
constraints, or you need very high speed.

-- 
Lew
0
Lew
3/25/2010 12:11:35 AM
On 24-03-2010 20:11, Lew wrote:
> Robbo wrote:
>>> I would be glad, if you could tell me, what is the reason
>>> for existing of SAXParserFactory, since there are better
>>> (faster in coding) solutions? Somebody uses SAXParserFactory
>>> and if yes, for what purposes?
>>> I use SAXParserFactory and it is quite much work to
>>> do with bunch of "if" instructions, boolean variables...
>
> Arne Vajhøj wrote:
>> SAX is great for parsing huge XML files where you
>> only need some of the information.
>
> Or all the information but not in the document's structure, or you have
> memory constraints, or you need very high speed.

SAX and StAX is for huge XML files.

If I actually needs all the data, then I would tend to
prefer StAX, but if I only need some of the data, then
SAX may be better.

For a small document even though I do not need the
XML structure, then I would use DOM and XPath to pick with.
The code is more readable.

Arne
0
UTF
3/25/2010 1:29:22 AM
On 24-03-2010 20:10, Lew wrote:
> Arne Vajhøj wrote:
>> But you still need a bunch of if statements [for SAX parsing].
>
> I've written a handful of SAX-parser based applications, starting with
> my first paid Java gig eleven years ago. There really weren't many 'if'
> statements in them; mostly I just instantiated an object based on the
> tag being processed, using a Map to look up the appropriate handler. In
> this it was similar to MVC code for servlets where you look up the
> handler based on a request parameter.

But in the case we are discussing, then the same tag appears in
multiple contexts. That requires if statements.

>> And the final code can easily become a bit messy.
>
> That's on the programmer, not the library.

Using SAX to parse the type of XML documents we are talking
about has to contain if statements and other solutions does
not.

>> I would prefer alternatives if they exists and are
>> usable in the context.
>
> SAX is /non pareil/ for the areas where it shines. Back in 1999, using
> Java 1.2 and then-current LAN tech (no gigabit or 100Mb/s LANs then) and
> the relatively low-memory machines of the day we could process on the
> order of a million hefty documents into or out of a database in about
> four hours using SAX. We were limited pretty much by transfer speeds not
> CPU because of the efficiency of SAX parsing.
>
> And there weren't a lot of 'if' statements involved, no more so than any
> other app I've worked on.

But given that we have a SAX_unfriendly structure of the XML
document and no indication that it is a huge file, then SAX is
not an obvious pick.

There are other cases where SAX do make sense. Even though StAX
has overtaken quite a few of those.

Arne

0
UTF
3/25/2010 1:33:10 AM
Arne Vajhøj wrote:
> On 24-03-2010 20:10, Lew wrote:
>> Arne Vajhøj wrote:
>>> But you still need a bunch of if statements [for SAX parsing].
>>
>> I've written a handful of SAX-parser based applications, starting with
>> my first paid Java gig eleven years ago. There really weren't many 'if'
>> statements in them; mostly I just instantiated an object based on the
>> tag being processed, using a Map to look up the appropriate handler. In
>> this it was similar to MVC code for servlets where you look up the
>> handler based on a request parameter.
> 
> But in the case we are discussing, then the same tag appears in
> multiple contexts. That requires if statements.

Not really.

Each tag holds a reference to its enclosing tag, so it already "knows" where 
belongs without need for 'if' statements.

>>> And the final code can easily become a bit messy.
>>
>> That's on the programmer, not the library.
> 
> Using SAX to parse the type of XML documents we are talking
> about has to contain if statements and other solutions does
> not.

You are mistaken.

>>> I would prefer alternatives if they exists and are
>>> usable in the context.
>>
>> SAX is /non pareil/ for the areas where it shines. Back in 1999, using
>> Java 1.2 and then-current LAN tech (no gigabit or 100Mb/s LANs then) and
>> the relatively low-memory machines of the day we could process on the
>> order of a million hefty documents into or out of a database in about
>> four hours using SAX. We were limited pretty much by transfer speeds not
>> CPU because of the efficiency of SAX parsing.
>>
>> And there weren't a lot of 'if' statements involved, no more so than any
>> other app I've worked on.
> 
> But given that we have a SAX_unfriendly structure of the XML
> document and no indication that it is a huge file, then SAX is
> not an obvious pick.


No one XML structure is more SAX-unfriendly than another.

> There are other cases where SAX do make sense. Even though StAX
> has overtaken quite a few of those.

-- 
Lew
0
Lew
3/25/2010 3:47:58 AM
Arne Vajh�j wrote:
> On 24-03-2010 13:09, bugbear wrote:
>> Arne Vajh�j wrote:
>>> On 23-03-2010 19:14, Robbo wrote:
>>>> I use SAXParserFactory to read data from XML files.
>>>>
>>>> Lets see some sample XML:
>>>>
>>>> <cyclogram>
>>>> <number>1</number>
>>>> <step>
>>>> <number>11</number>
>>>> </step>
>>>> </cyclogram>
>>>>
>>>> <cyclogram>
>>>> <number>1</number>
>>>> <step>
>>>> <number>11</number>
>>>> </step>
>>>> </cyclogram>
>>>>
>>>> Since "number" is both in "cyclogram" and "step" we
>>>> need to pursue if we are actually in "cyclogram" or in "step",
>>>> to decide if "number" is connected to "cyclogram" or to
>>>> "step".
>>>>
>>>> I wonder, if there are tools which could automatically
>>>> generate Java code for purpose of reading XML files.
>>>> For example, user of such tool could define structure
>>>> of XML file with use of some GUI (e.g. tree structure
>>>> graphicaly represented). After that user could press some
>>>> button and see Java code...
>>>> I hope you understand what I mean.
>>>
>>> Parsing that with SAX requires you to keep context.
>>
>> Yes - normally a simple tag stack is sufficient (push on start,
>> pop on end).
> 
> But you still need a bunch of if statements.
> 
> And the final code can easily become a bit messy.
> 
> I would prefer alternatives if they exists and are
> usable in the context.

One of the neatest solutions I've seen is this:

http://www.devsphere.com/xml/saxdomix/

It uses a SAX parser, but (on a configurable trigger) it will
build DOM representations of sub-trees. This sub-tree
can then be handled with the DOM technique
that suits you.

This is MASSIVELY appropriate for the common case
where an XML file is actually a set (or list)
of repeated sub-elements, e.g. a catalogue
of books, list of customer orders, etc.

You get the convenience of DOM processing on the
(e.g.) book nodes without the normal DOM overhead
of having the whole XML file in RAM at once.

     BugBear
0
bugbear
3/25/2010 9:42:08 AM
On 25-03-2010 05:42, bugbear wrote:
> Arne Vajh�j wrote:
>> On 24-03-2010 13:09, bugbear wrote:
>>> Arne Vajh�j wrote:
>>>> On 23-03-2010 19:14, Robbo wrote:
>>>>> I use SAXParserFactory to read data from XML files.
>>>>>
>>>>> Lets see some sample XML:
>>>>>
>>>>> <cyclogram>
>>>>> <number>1</number>
>>>>> <step>
>>>>> <number>11</number>
>>>>> </step>
>>>>> </cyclogram>
>>>>>
>>>>> <cyclogram>
>>>>> <number>1</number>
>>>>> <step>
>>>>> <number>11</number>
>>>>> </step>
>>>>> </cyclogram>
>>>>>
>>>>> Since "number" is both in "cyclogram" and "step" we
>>>>> need to pursue if we are actually in "cyclogram" or in "step",
>>>>> to decide if "number" is connected to "cyclogram" or to
>>>>> "step".
>>>>>
>>>>> I wonder, if there are tools which could automatically
>>>>> generate Java code for purpose of reading XML files.
>>>>> For example, user of such tool could define structure
>>>>> of XML file with use of some GUI (e.g. tree structure
>>>>> graphicaly represented). After that user could press some
>>>>> button and see Java code...
>>>>> I hope you understand what I mean.
>>>>
>>>> Parsing that with SAX requires you to keep context.
>>>
>>> Yes - normally a simple tag stack is sufficient (push on start,
>>> pop on end).
>>
>> But you still need a bunch of if statements.
>>
>> And the final code can easily become a bit messy.
>>
>> I would prefer alternatives if they exists and are
>> usable in the context.
>
> One of the neatest solutions I've seen is this:
>
> http://www.devsphere.com/xml/saxdomix/
>
> It uses a SAX parser, but (on a configurable trigger) it will
> build DOM representations of sub-trees. This sub-tree
> can then be handled with the DOM technique
> that suits you.
>
> This is MASSIVELY appropriate for the common case
> where an XML file is actually a set (or list)
> of repeated sub-elements, e.g. a catalogue
> of books, list of customer orders, etc.
>
> You get the convenience of DOM processing on the
> (e.g.) book nodes without the normal DOM overhead
> of having the whole XML file in RAM at once.

That sounds pretty cool !

Arne
0
ISO
3/25/2010 11:09:17 PM
On 24-03-2010 23:47, Lew wrote:
> Arne Vajhøj wrote:
>> On 24-03-2010 20:10, Lew wrote:
>>> Arne Vajhøj wrote:
>>>> But you still need a bunch of if statements [for SAX parsing].
>>>
>>> I've written a handful of SAX-parser based applications, starting with
>>> my first paid Java gig eleven years ago. There really weren't many 'if'
>>> statements in them; mostly I just instantiated an object based on the
>>> tag being processed, using a Map to look up the appropriate handler. In
>>> this it was similar to MVC code for servlets where you look up the
>>> handler based on a request parameter.
>>
>> But in the case we are discussing, then the same tag appears in
>> multiple contexts. That requires if statements.
>
> Not really.
>
> Each tag holds a reference to its enclosing tag, so it already "knows"
> where belongs without need for 'if' statements.

It does ?

How do you in startElement get a ref to the enclosing tags (potentially
recursively) ?

>>>> And the final code can easily become a bit messy.
>>>
>>> That's on the programmer, not the library.
>>
>> Using SAX to parse the type of XML documents we are talking
>> about has to contain if statements and other solutions does
>> not.
>
> You are mistaken.

It would not be the first time.

>>>> I would prefer alternatives if they exists and are
>>>> usable in the context.
>>>
>>> SAX is /non pareil/ for the areas where it shines. Back in 1999, using
>>> Java 1.2 and then-current LAN tech (no gigabit or 100Mb/s LANs then) and
>>> the relatively low-memory machines of the day we could process on the
>>> order of a million hefty documents into or out of a database in about
>>> four hours using SAX. We were limited pretty much by transfer speeds not
>>> CPU because of the efficiency of SAX parsing.
>>>
>>> And there weren't a lot of 'if' statements involved, no more so than any
>>> other app I've worked on.
>>
>> But given that we have a SAX_unfriendly structure of the XML
>> document and no indication that it is a huge file, then SAX is
>> not an obvious pick.
>
> No one XML structure is more SAX-unfriendly than another.

Correct if you can get the enclosing element as you claim.

Arne
0
UTF
3/25/2010 11:13:03 PM
Arne Vajhøj wrote:
>>>>> But you still need a bunch of if statements [for SAX parsing].

Lew wrote:
>>>> I've written a handful of SAX-parser based applications, starting with
>>>> my first paid Java gig eleven years ago. There really weren't many 'if'
>>>> statements in them; mostly I just instantiated an object based on the
>>>> tag being processed, using a Map to look up the appropriate handler. In
>>>> this it was similar to MVC code for servlets where you look up the
>>>> handler based on a request parameter.

Arne Vajhøj wrote:
>>> But in the case we are discussing, then the same tag appears in
>>> multiple contexts. That requires if statements.

Lew wrote:
>> Not really.
>>
>> Each tag holds a reference to its enclosing tag, so it already "knows"
>> where belongs without need for 'if' statements.

Arne Vajhøj wrote:
> It does ?
> 
> How do you in startElement get a ref to the enclosing tags (potentially
> recursively) ?

It's been a long time since I've done one, so I don't have code samples handy. 
  I apologize; this would be so much easier if I did.

I derive from the parser class 'DefaultHandler' a custom implementation for 
each tag (element).  One member of that implementation is 'parent', which gets 
set each time an enclosing element hands off to the handler for an enclosed 
element.  You can follow the 'parent' members in a chain right back to the 
root element if you need to.

The 'endElement()' method returns control back to the enclosing handler.

This is not so very different from bugbear's suggestion that
> normally a simple tag stack is sufficient 
> (push on start, pop on end). 

It worked beautifully every time I've used it, including back in 1999 on that 
first parsing project that used a pretty decent-sized DTD for each document 
type and had quite ambitious performance goals, which we exceeded handily.

-- 
Lew
0
Lew
3/26/2010 12:12:22 AM
On Wed, 24 Mar 2010, Mayeul wrote:

> (Confession: I don't have a clue about StAX. It might be good.)

It's pretty good.

tom

-- 
life finds a way
0
Tom
3/26/2010 3:06:05 AM
On Wed, 24 Mar 2010, Arne Vajh?j wrote:

> On 24-03-2010 20:10, Lew wrote:
>> Arne Vajh?j wrote:
>>> But you still need a bunch of if statements [for SAX parsing].
>> 
>> I've written a handful of SAX-parser based applications, starting with 
>> my first paid Java gig eleven years ago. There really weren't many 'if' 
>> statements in them; mostly I just instantiated an object based on the 
>> tag being processed, using a Map to look up the appropriate handler. In 
>> this it was similar to MVC code for servlets where you look up the 
>> handler based on a request parameter.
>
> But in the case we are discussing, then the same tag appears in
> multiple contexts. That requires if statements.

Nope. Maintain a tag stack as a List<String>. Use the stack as a key into 
a Map<List<String>, Handler> to retrieve a handler specific to the tag in 
its context. I've written code like this, works quite nicely.

If i had to do it again, i'd use StAX instead.

tom

-- 
life finds a way
0
Tom
3/26/2010 3:08:18 AM
Reply: