File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes SAX parsing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "SAX parsing" Watch "SAX parsing" New topic
Author

SAX parsing

Sandeep Lakshmipathy
Ranch Hand

Joined: Mar 05, 2002
Posts: 31
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


Sandeep Lakshmipathy
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
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).
Sandeep Lakshmipathy
Ranch Hand

Joined: Mar 05, 2002
Posts: 31
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

Joined: Mar 17, 2000
Posts: 5782
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SAX parsing