aspose file tools
The moose likes XML and Related Technologies and the fly likes SAX parser's characters[] method Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Reply Bookmark "SAX parser Watch "SAX parser New topic
Author

SAX parser's characters[] method

Tiju Thomas
Greenhorn

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.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

Joined: Mar 22, 2000
Posts: 12271
    
    1
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


Java Resources at www.wbrogden.com
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: SAX parser's characters[] method
 
Similar Threads
Event calling for characters method
Print out values of xml tags
character method of ContentHandler
How can I convert the xml to a string?
getting attribute value in java