This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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
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.
Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Joined: Mar 05, 2002
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.
Joined: Mar 17, 2000
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.