This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell 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.