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 52272 articles. 40 followers. Post Follow

21 Replies
219 Views

Similar Articles

[PageSpeed] 25
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:
Similar Artilces:

Opensource tool for Software Architect
Hi, Is anyone know any opensource & paid tool which will help to maintain class hierarchy. Also suggest some tools, which helps to "Software Architect" for maintaining the system flows. Regards, Mahendra Bhandarkar On 18 Mrz., 06:04, manoj <mahendrabhandar...@gmail.com> wrote: > Is anyone know any opensource & paid tool which will help to maintain > class hierarchy. There are a ton of UML tools out there, if you want coupling of Java and UML you need to look for "reverse engineering" or "roundtrip" capabilities. Examples: ...

serial read problems
Hello, I'm trying to read data continuously from a PLC using labview, and all the information I have consists of the data rate, bits, and parity. This is all set correctly. It also mentions that a carriage return and line feed separate each group of readings. I don=92t believe it supports flow control? I'm using the advanced serial read/write example, and when I go to read, it runs fine, and I set the read bytes to 40 (the actual bytes counter says 40), I get the datastream of what I=92ve expected, but after a while it times out, and I can't connect again until I reboot. I've...

which java versionon PCs
Do most people who already have a jre installed have the latest 1.6 version or do u think most would still be on 1.5 or less? Im wondering what minimum version to require on for my free download java application. If very few have 1.6 it would be slower/tedious to force them install 1.6 TIA ...

Cancel point and/or timeouts for read/write lock waits...
Are they necessary? How many of you actually rely on a read/write lock timing out, or even canceling, to drive your applications? I think sync. algos's that "need to be unlocked", ie: mutex, rw-mutex, ect.. should not be a cancellation point... This is because, it seems, cancel points are great for long waits. Why would an application create a critical section that makes threads wait for extended periods of time? That seems like a bad design. So, please enlighten me on the importance of cancelable read/write locks... Thanks! :) SenderX wrote: > A...

Looking for Java/J2EE/WebSphere Training Resources
Hi folks: I'm part owner of a training company historically associated with clients who use IBM software. We are looking for independent training resources who can provide both the skills to teach and course materials to match the following "broad" topics. Java & J2EE Programming WebSphere Development &/or Administration Please respond directly to me at: jwynton@gmail.com Thanks, John Wynton ...

Re: PROC GLM's "Class" statement (vs. using dummy coding for qualvariables)
Thanks for this info, Paul. In case anyone at SAS is listening in, wouldn't it make sense to change the message you get so that it doesn't worry people? Peter Peter L. Flom, PhD Assistant Director, Statistics and Data Analysis Core Center for Drug Use and HIV Research National Development and Research Institutes 71 W. 23rd St www.peterflom.com New York, NY 10010 (212) 845-4485 (voice) (917) 438-0894 (fax) >>> Paul R Swank <Paul.R.Swank@UTH.TMC.EDU> 9/21/2004 5:46:34 PM >>> All GLMs with class statements have singular matrices since GLM automatically puts i...

Reporting Tools Comparison
I am doing some research on reporting tools and I need to: - Find and evaluate report creation/maintenance tools suitable for both the thick client as well as thin client - Come up with a list of tools, prices, license restrictions, pros, cons and a brief description Does anyone have any suggestions/recommendations? ...

ARM code to load signed half-words from memory
Greetings, I thought some of you might be interested in the following analysis of a C program that heavily uses 16 bit ('short') integers. I recently recompiled it using the Norcroft C compiler with the appropriate options to prevent unaligned data accesses (for compatibility with ARM architecture version 6 and later). I found that the executable file had grown noticeably as a result, and disassembled the code to find out why. ARM architectures [1 ... 5] (max. 3 instructions per load) --------------------------- An assembly language programmer: CMP R3,#0 LDREQ R12,[R0,#0] ; u...

How can I get rid of "nonfinites" from code generated from MPC block?
I am generating code for an MPC controller using a modified "ert" system target file and this produces the functions "rt_nonfinite.*" that initializes non-finites; i.e. "inf" and "NaN". The problem is my target, a simulation environment, doesn't seem to like these files. I have put bounds on my inputs and outputs and tried to remove any non-finite value from all the parameters but it's not enough. Is there any way to remove all non-finites from the MPC block when generating code? Also, apparently the MPC block refers to a non-inlined function. H...

QuickLook generator plugin
Hi NG I try to program a .qlgenerator for my documents. It generates a rtf-data form the document hands it over in the QLPreviewRequestSetDataRepresentation (preview, (CFDataRef)theRTF, kUTTypeRTFD, NULL); function. I use qlmanage to debug the plugin. I always get this error: [<QLPreviewView 0x1321b0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key isRealPreview. I don't know what that means and I can't find any documentation about "isRealPreview". Thanks a lot - Florian. Florian Zschocke <edv@z...

Is there a possibility to call a stored procedure on the MSSQL DB without java to wait for a return value?
Hello Im working with jdbc on a MSSQL Database. In my java client im executing a stored procedure called myProc on the database. Im doing this with the following code: ...... Statement stmt = con.createStatement(); String sql1 ="execute myProc"; stmt.execute(sql1); My problem is, that this stored procedure takes at least one hour to finish. So i cant close the java client during this time, otherwise the stored procedure will be canceled. I can call it in a seperate thread, but that doesnt help. Nevertheless the client cant be closed. Is there a possibility to call a stored proced...

Which DICOM Tool?
I am in the process of evaluation different DICOM tools for VB. Can anyone recommend one? Ones to avoid? Thanks. ...

US-TX-Austin: Sr. Oracle DBA, 7.x/8i/9i, RDBMS, Java, RAC, Sun Solaris or Linux; (45326557606)
US-TX-Austin: Sr. Oracle DBA, 7.x/8i/9i, RDBMS, Java, RAC, Sun Solaris or Linux; (45326557606) ============================================================================================== Position: Sr. Oracle DBA Reference: SMC01728 Location: Austin TX Duration: 1Y Skills: BS or MS to include a minimum of twelve (12) hours in management science, computer science, information systems, and/or data processing. 5+yrs exp using Oracle Enterprise Edition (7.x, 8i and 9i) RDBMS, with recent exp with Oracle 9i...

[ace-users] TOOLS
Hi Folks, The following conference next summer in Switzerland may be of interest to ACE+TAO+CIAO developers and users. Take care, Doug =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D TOOLS EUROPE 2007 Objects, Models, Components, Patterns ETH Zurich, Switzerland 24-28 June 2007 =09=09=09=09=20=20 ...

XML Toolbox
I'm hoping to use the XML Toolbox: http://www.mathworks.com/matlabcentral/fileexchange/4278 for a project im currently doing. Is this the best one out there or is there a more recent method for exporting XML from Matlab.. Oh and how do I install it?? Ive never used toolboxes before... (using Matlab 7.6.0 (R2008a) ) Any help appreciated. "Matt Stuttard" <matt@msfx.co.uk> wrote in message <gou3vl$hv$1@fred.mathworks.com>... > I'm hoping to use the XML Toolbox: > > http://www.mathworks.com/matlabcentral/fileexchange/4278 > > for a project im ...

writing a file picture
Hello, &nbsp; i got a problem with this VI. actually i'm truing to write an acquiring images to a folder. but nothing happen. my images are png (type). i attached the which one give more explanation. could someone help me with this issue please? &nbsp; Regards, &nbsp; Tchaou load1.vi: http://forums.ni.com/attachments/ni/170/238397/1/load1.vi Hi G1L, when i'm runing my program it gives as error : " Error -1074395992 occurred at IMAQ WriteBMPFile&nbsp; File access denied." do you know why ? Regards, Tchaou Hi, tanks i was using a 16 bit image. Regards, Tchao...

Help with this loop code please
Dear forum, I am trying to solve this problem in matlab. I am currently executing the following loop - K = 4; % Loop for i=1:K, b(i) = (x^2) / (1 - (2*cos(d(i))) + (x^2)); end I am then manually inserting the computed values of b into an array such as this - B1 = [b(1) (2*b(1)) b(1)]; B2 = [b(2) (2*b(2)) b(2)]; B3 = [b(3) (2*b(3)) b(3)]; B4 = [b(4) (2*b(4)) b(4)]; However, I would like to simultaneously fill the array for B in the same loop as from time to time the value for K may change. Any ideas? Thanks, Kath Kath wrote: > > Dear forum, > > I am trying to sol...

automatic file generation
What I want to do is write data to a spreadsheet file and have this file named from a user input string earlier in the code ( I am passing all the user inputs through each&nbsp;VI via clusters). For example, one of the user inputs is "Unique Valve ID Number". Therefore when I write my data to a spreadsheet, I automatically want the file name to be the Unique valve ID number without a dialogue box appearing asking me to type this in. I also want the file to be save automatically to a specific location on my network every time. &nbsp; As a result each time I log a test, the fi...

how to read a file and insert it into a mysl blob field
How can I read a localy stored file and insert it into a mysal blob field? Thanx -- Jochen Jochen Kaechelin wrote: > How can I read a localy stored file and insert it into a mysal blob > field? > require 'mysql' begin dbh = Mysql.real_connect('localhost', 'username', 'passwd', 'database') data = File.read('data.txt') #get the data out of the file data = dbh.escape_string(data) #escape any quotes in the data dbh.query(" INSERT INTO table_name (char_field, int_field, tinyblob_field) VALUES ...

FAST!!! release stucked file "j7FD45LC003484"
Hi, I need to release a mail in the format: " Return-Path: <~Ag> Received: from ... X-Spam-Filter: c... Date: Mon, 15 Aug 2005 16:04:17 +0300 From: FLO... Subject: V... To: TSI... (lots of users ) CC: lots of mails ... This is a multi-part message in MIME format... ... Content-type: application/x-msexcel; name="1.xls" Content-transfer-encoding: base64 Content-Disposition: attachment; filename="1.xls" .... " The mail was caught by mailscanner (which I removed today, leaving only sendmail 8.x running). I need to: a) release the file from quarantine ( I trie...

FTP source code
I've been looking at Apple's developer site for hints on how to build FTP support within an application. I was directed to CFFTPSample and the CFFTPStream class, but I'm finding this inadequate. I need to be able to carry on a dialog with the FTP server and send commands like RETR, CWD, etc. Is there a Cocoa/Foundation way to do this or should I just go with OmniNetworking from the OmniGroup? I haven't looked at OmniNetworking just yet, so I don't know what its strengths/weaknesses are. But in the long term I want to support GSSAPI, so that's a considerati...

Problem of memory liberation on an application Java (GUI swing) under Windows 2000 with the jre 1.4.1_02.
Hello, I have an application Java who is bounded to 64Mb. This application instanciate a certain numbers of objects to attain about 30Mb a thrown time. On some actions, the application instanciate again the same objects. The used memory increases in consequence. First objects are not more referenced. Normally, for all objects not referenced, the memory ought to be recoverred by the garbage collector. The memory ought to maintain to about 30 Mb. But, It's not the case. By forcing the garbage collector by System gc() or System runFinalization() and tracing methods finalize() called on some ...

US-TX-Austin: Engineering Assoc., Read/interpret wiring diagrams, spreadsheets; (45326032402)
US-TX-Austin: Engineering Assoc., Read/interpret wiring diagrams, spreadsheets; (45326032402) ============================================================================================= Position: Engineering Assoc. Reference: SMC01714 Location: Austin TX Duration: 1Y Skills: BS in Electrical Engineering or Engineering technology Exp reading and interpreting wiring diagrams and schematics for SCADA, metering and protective relaying. Computer competence with Windows environment and experience using MS E...

load text-data from file
hi i have very large ascii files with data that i need to read. Sometimes text can be at the place where usually numbers are (errors, alarmText etc) Se below for an illustrative example: Mass:Some:Hey 1:34:32 2:error:221 3:43:343 4:32:12 I try importdata with : as delimiter, this understands the header-row and reads the first line correctly but messes up the second (says both pos 2 and 3 is NaN) and stops reading (both row 3 and 4 is skipped altogether). Could i get this to work? The other thing i tried is using textScan and if i specify each position as reading a string (%s) and...

Intermixing clocking blocks, interfaces and tb code..
Hi everyone, I'm trying to understand how to properly use clocking blocks and interfaces in both synthesis code (where the clocking block is ignored) and test bench code where it is used, and I'm not really sure what the expected standard behavior should be.. For instance, if I have an interface like this: interface foo(input logic Clk); logic A; logic B; clocking cki @(posedge Clk); input A; output B; endclocking; clocking cko @(posedge Clk); output A; input B; endclocking; modport STB(clocking cki, clocking ck...