Hi Michael, I tried the following example with Xerces-J 2.9.1. XML document is:
<root> <abc>hello</abc> <pqr/> <uvw/> </root> Source program is: public class SAXempl extends DefaultHandler { .............. .............. public static void main(String[] args) { SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser parser = spf.newSAXParser(); parser.parse(new File(filename), this); } public void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, Attributes attributes) { System.out.println("-----start element-----"); System.out.println("#"+uri+"#"); System.out.println("#"+localName+"#"); System.out.println("#"+qName+"#"); System.out.println("!-----start element-----!"); } public void endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName) { System.out.println("------end element------"); System.out.println("#"+uri+"#"); System.out.println("#"+localName+"#"); System.out.println("#"+qName+"#"); System.out.println("!------end element------!"); } public void characters(char[] ch, int start, int length) { System.out.println("------characters------"); System.out.println((new String(ch)).trim()); System.out.println("!------characters------!"); } I have omitted the imports and other class skeleton for brevity. When I run this program on the above XML file, I get following output: -----start element----- ## ## #root# !-----start element-----! ------characters------ root> <abc>hello</abc> <pqr/> <uvw/> </root> !------characters------! -----start element----- ## ## #abc# !-----start element-----! ------characters------ root> <abc>hello</abc> <pqr/> <uvw/> </root> !------characters------! ------end element------ ## ## #abc# !------end element------! ------characters------ root> <abc>hello</abc> <pqr/> <uvw/> </root> !------characters------! -----start element----- ## ## #pqr# !-----start element-----! ------end element------ ## ## #pqr# ------characters------ root> <abc>hello</abc> <pqr/> <uvw/> </root> !------characters------! -----start element----- ## ## #uvw# !-----start element-----! ------end element------ ## ## #uvw# !------end element------! ------characters------ root> <abc>hello</abc> <pqr/> <uvw/> </root> !------characters------! ------end element------ ## ## #root# !------end element------! I am a bit perplexed by the following output from 'characters' event: root> <abc>hello</abc> <pqr/> <uvw/> </root> Moreover, if I don't do trim() on the String object, I get lot of whitespaces in the output. Could you kindly explain this behaviour by Xerces. On Jan 26, 2008 12:27 AM, Michael Glavassevich <[EMAIL PROTECTED]> wrote: > I suppose the SAX spec doesn't forbid that but Xerces doesn't do that. > You'll get a startElement() event followed by an endElement() event. The > only exception to that is if you're doing schema validation and the > validator inserted a default element value. Then you'll get a characters() > event. -- Regards, Mukul Gandhi --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]