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

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
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: 13018
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.

Consider Paul's rocket mass heater.
subject: SAX parser's characters[] method
jQuery in Action, 3rd edition