• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

parse many xml file

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone, I am doing a project that I need to parse may different xml config files, such as struts config and tiles config and some other with different structures. My question is that if I use SAX, do I need to create parser for each file or I just create one for all? If there is only one parser, I worry about the if statement will go too large and mess. Is there a better way if I only use SAX ?

Thanks
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that trying to re-use a SAX parser would be a mistake. But note that you can re-use the same instance of SAXParserFactory.

Perhaps you meant re-use the same handler for the SAX events? That would indeed lead to a mess.

If this was my problem I would look into the Apache Commons Digester project.

Bill
 
con wan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

William Brogden wrote:I think that trying to re-use a SAX parser would be a mistake. But note that you can re-use the same instance of SAXParserFactory.

Perhaps you meant re-use the same handler for the SAX events? That would indeed lead to a mess.

If this was my problem I would look into the Apache Commons Digester project.

Bill



Thanks for your reply.

Yes, what I consider is to re-use the same handler for SAX events. I think there would be a mess too. I am still looking for the better tool than SAX.
The reason I use SAX is because my app should handle different structure of xml. So I should create a lot of objects for one xml file if I use Digester. If a lot of xml files, I create a lot of objects, thats heavy. For SAX, I just add a lot of if statement in the startElement() method for searching for a tag or attributes.
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Seems to me the important question is - how many values do you need to keep out of each configuration file?

If you only need one or two, sure, the SAX parser (or perhaps StAX because it is easier to stop parsing once the value is found.)

On the other hand if you need many values extracted, it is purely false economy to create hard to debug and maintain monster SAX handler class(es) - this counts as premature optimization. (The root of all evil as all programmers should remember.) In that case, just build the darn objects and go on to more important architectural tasks. Or - just build the DOMs, apply XPATH to get the values and discard the DOM - slow but oh so easy to maintain.

So - how much of the data in a typical conf file do you need? When do you need it? Do you have to re-read it often?

Bill
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic