File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes SAX parser's characters[] method 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 parser Watch "SAX parser New topic

SAX parser's characters[] method

Tiju Thomas

Joined: May 25, 2008
Posts: 22
My characters method overridden from the DefaultHandler for SAX parsing is returning a character less

My xml is <resource>All Roles1/UOP[XIY]</resource>

The characters method is returning only "All Roles1/UOP[XIY"

public void characters(char[] ch, int start, int length) throws SAXException
String cdata = new String(ch,start,length);

activeHandler is a TagActionHandler object

I have even tried <resource><![CDATA[All Roles1/UOP[XIY]]]></resource> to no avail
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13036
Everybody runs into this when starting with SAX.

You can never count on characters() getting an entire String from a text element. As explained in the JavaDocs, a parser may call characters multiple times as it works its way through one or more bufferloads read from an input stream. It is up to you the programmer to handle this.

I agree. Here's the link:
subject: SAX parser's characters[] method
It's not a secret anymore!