• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

SAX parsing

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Friends,
I am new to XML. When I use the Sax parser to parse an xml file, the control comes to the characters(..) method more than once for a single element value which i happen to store in a String.
To avoid multiple entries to this method, I am using a boolean value to this. Is this a natural behaviour of the parser, or i am going wrong some where . Thanks in advance
Sandeep
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. It is the natural behaviour of the SAXParser. The character method may be called multiple number of times.
The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity.
The application must not attempt to read from the array outside of the specified range indicated by the start index and end index parameters.

Hope that helps.
 
Sandeep Lakshmipathy
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ajith.
This means its better I use the StringBuffer instead of String variable to store the char chunks as they arrive for a single element's value. By this, I can discard the use of the boolean variable that I now presume is an incorrect implementation since the same value could come in one or more chunks and I am expected to wait and append all those chunks to get the full value for the element. Please correct me if wrong.
Thanks a lot.
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you are correct. You can simply read the characters from argument array within the start to end range and keep appending them to a StringBuffer. That will work.
 
reply
    Bookmark Topic Watch Topic
  • New Topic