File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to store values in a ArrayList from startElement?

 
Tariq Ahsan
Ranch Hand
Posts: 116
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anybody have any code samples where I can read an extremely big XML file using strictly SAX and store each of the element values into a vector or preferably an ArrayList? Later I would like to iterate through this vector/list from main or some other class.

Would appreciate a lot for any sort of help!!!
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13045
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is nothing magic about SAX that prevents you from using standard Java techniques. You just have to adjust to the "callback" style of event processing.

You have to write a custom startElement method in your custom handler class - in that method, select the data you want to keep and store it in an ArrayList that is an instance variable of your custom handler class.
When you get the endDocument event, you know the complete document has been processed and your ArrayList has all the data. You can do further processing in the handler or with the Thread that called the parser.
Bill
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic