This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
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: 12759
    
    5
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: SAX parser's characters[] method
 
Similar Threads
character method of ContentHandler
How can I convert the xml to a string?
Event calling for characters method
getting attribute value in java
Print out values of xml tags