Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

retrieving data from SAX parser  RSS feed

 
Michael Lipton
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
does anyone know how to actually get the data that has been parsed from a SAX parser....
i understand that you override the endDocument, endElement, etc methods, but if i want to store data parsed by those methods into an array and pass the array to another class - how can i do that??
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you override 'startElement', you can get at the names of the elements and the attributes through the method parameters. If you override 'characters', you get the text between tags through its parameters. Is that what you are looking for? If not, then describe in more detail where you're stuck.
 
Michael Lipton
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no, i have that part... but it seems that those methods are great if you can handle the data inside the StartElement methods (or other overloaded method)
what i would like to do is have an array that holds the data of some elements... once the parser is done, i want to send that array to another class for processing, but i cant find a nice way to do this
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Keep a List (e.g. "List elements = new ArrayList()") outside of the SAX methods. Then in startElement you can call "elements.add(localName)", thus remembering the succession of elements in the document. After endDocument is called you can then use that List in whatever way you need to.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!