From: Robbo on
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


From: Robbo on
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


From: Roedy Green on
On Wed, 24 Mar 2010 00:14:27 +0100, "Robbo" <nie.mam(a)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.
From: Roedy Green on
On Wed, 24 Mar 2010 17:12:26 +0100, "Robbo" <nie.mam(a)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.
From: Lew on
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