Lingzhi Zhang wrote:
Hi,
I am trying to XML serializer to format a XML file that I frequently change. I want to keep everything in the original document there (e.g. comment), just use the XML serializer to format the document. I found that using DefaultHandler2 has a comment callback, however, it seems that it didn't work, since i didn't see anything is printed in that method. Other than that, if I get the comment() call back, how can I make the ContentHandler to write the comment into output stream. Any hint would be appreciated. Steve. My code is like:

Hi,

as far as I understand this, DefaultHandler2 implements the LexicalHandler interface which contains the requested method. However, the parse method only takes a DefaultHandler and is therefore unaware of the implemented LexicalHandler interface. So IMHO you have to explicitly tell the parser about an implementation of LexicalHandler via the Parser.setProperty method, i.e.

  parser.setProperty ("http://xml.org/sax/properties/lexical-handler";, handler);

just before calling the parse method. See also the JavaDoc for the org.xml.sax.ext.LexicalHandler interface. By the way, the XMLSerializer also implements the LexicalHandler interface, so you could directly specify it in the setProperty call and your adapter class wouldn't need to take care of it.

greetings,

Klaus

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

Reply via email to