hi,
I've been looking through the various XML parsers API available and I have
decided to use the SAX parser. Probably not the best of choices but I think
it can do the job. What is the best way to parse an XML file using the SAX
parser ? I have seen examples where they store each element tag in java bean
classes. I am not sure this is a good way for my XML file which looks like
this:
<parent>
<node1>
<child1>AAA</child1>
<grandchild1>BBB</grandchild1>
<grandchild2>
<anything>CCC</anything>
</grandchild2>
<child2>DDD<</child2>
<child3>DDD<</child3>
</node1>
<node2>
<child1>AAA<</child1>
<grandchild1>BBB</grandchild1>
<grandchild2>
<anything>CCC</anything>
</grandchild2>
<child2>DDD<</child2>
<child3>DDD<</child3>
</node2>
</parent>
I have to get the value of the tag "anything" in node1, node2 etc ..., store
the value of child3 in a database etc ...
Does anyone have any experience or advices regarding the fastest way to do
that using SAX (or any other parser) ?
Thanks !
HalcyonWild - 12 Aug 2005 20:09 GMT
Use DOM. It maps our thinking about XML better. You can visualize the
tree with DOM. A bit slower, but its OK. Probably, your DB insert code
will take the longest time.
hawat.thufir@gmail.com - 12 Aug 2005 22:35 GMT
...
> I have to get the value of the tag "anything" in node1, node2 etc ..., store
> the value of child3 in a database etc ...
[quoted text clipped - 3 lines]
>
> Thanks !
What's meant by "fast"? Fastest development or fastest execution?
I'm reading chapters 5-6 of
<http://java.sun.com/j2ee/1.4/docs/tutorial/doc/index.html>. I believe
that SAX <http://www.saxproject.org/> has a faster developement.
There's also JDOM <http://www.jdom.org/> and DOM4j
<http://www.dom4j.org/>.
DOM is designed to work with a variety of languages, such as Perl,
which can be a downside if you're doing everything else in Java, I
would think.
I'd be very interested in how you're going to do your db insertions,
and which database you select :)
-Thufir