• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SAX parser's characters[] method

 
Tiju Thomas
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.setParameterValue(activeParameter,cdata);
}

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
Rancher
Posts: 13055
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic