• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

parse XML files present in a directory

 
amitesh kumar
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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

Amitesh
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are you stuck on? Listing the files in the directory or parsing XML? What have you tried so far?
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
amitesh kumar
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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. ;)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic