aspose file tools*
The moose likes XML and Related Technologies and the fly likes parse XML files present in a directory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "parse XML files present in a directory" Watch "parse XML files present in a directory" New topic
Author

parse XML files present in a directory

amitesh kumar
Ranch Hand

Joined: Aug 01, 2006
Posts: 50
Hi,

I've to parse each n every XML files present in a directory. Please someone help me.

Amitesh
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

What are you stuck on? Listing the files in the directory or parsing XML? What have you tried so far?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Sounds like you need straight coding example for parsing XML's.

Look at this tutorial.
Many things are there to consider before taking the decision as which parser to choose.
like size of file , why exactly are you parsing and stuffs like that.
Hope this helps,


Rahul Bhattacharjee
LinkedIn - Blog
amitesh kumar
Ranch Hand

Joined: Aug 01, 2006
Posts: 50
Hi,

Actually i have to parse XMLs in python but for another attempt I'm looking for other options. Attempt is like:

1. Read each XML file in a folder.
2. Parse file.
3. Store some of the tags values as key-value pair in a map
4. Similarly maintain another collection that'll store one map per file.


To achieve this the current python attempt is like:



Now can someone provide me help. Even if i get a solutions in Java it's not a problem.

Thanks

- Amitesh
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
I would have tried the problem in the following manner.

Create a map of map.Key to the first map would be the name of the file and value would be another map that would store the required key:value pairs.
So this would be the data structure.

Parse the file using SAX parser.I guess key would be the name of the element and value would be the text within the element markup.
amitesh kumar
Ranch Hand

Joined: Aug 01, 2006
Posts: 50
Hi Rahul,

Thanks for your suggestion. Can you please provide me with some links or sample code that I can refer to in order to learn Java-based SAX parsing.

Thanks,

Amitesh
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Originally posted by amitesh kumar:
Can you please provide me with some links or sample code that I can refer to in order to learn Java-based SAX parsing.


You can find that in my first reply to this post. ;)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: parse XML files present in a directory