Sat, 26 Jan 2008 10:44:32 +0530, /Mukul Gandhi/:

[...]
   public void characters(char[] ch,
                          int start,
                          int length) {
     System.out.println("------characters------");
     System.out.println((new String(ch)).trim());
     System.out.println("!------characters------!");
   }
[...]
When I run this program on the above XML file, I get following output:
[...]
------characters------
root>
  <abc>hello</abc>
  <pqr/>
  <uvw/>
</root>
[...]
I am a bit perplexed by the following output from 'characters' event:

root>
  <abc>hello</abc>
  <pqr/>
  <uvw/>
</root>

You example is obviously wrong. You need to honor the 'start' and 'length' parameters passed to the 'characters' callback when constructing a String out of the given 'ch':

new String(ch, start, length)

Moreover, if I don't do trim() on the String object, I get lot of whitespaces in the output.

You use System.out.println(...) which adds a new-line to the output.

At the end, all you have shown does not indicate Xerces generates 'character' callbacks between the 'startElement' and 'endElement' callbacks for empty elements. Just pay attention to your output (now, after you know your 'character' callbacks output is wrong, just ignore it):

startElement: root
characters: ...
startElement: abc
characters: ...
endElement: abc
characters: ...
startElement: pqr
endElement: pqr
startElement: uvw
endElement: uvw
characters: ...
endElement: root

Where do you see character callbacks in between the start and end element callbacks for the "pqr" and "uvw" elements?

--
Stanimir

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to