Hello,
Firstly apologies if I've got the wrong list: This is a question about the use of the org.apache.xml.serializer package which comes in xalan.jar - but I'm not using it with Xalan/XSLT directly - instead, as a component in a SAX event pipeline. Please let me know if there's a better forum for this question.
What I'm trying to do, so far without sucess, is get the serializer to convert LexicalHandler.startDTD() and LexicalHandler.comment() events/callbacks into their textual form. I've got code which wraps DOCTYPEs into real XML markup at the start of my pipeline and I'm trying to convert these back to their textual forms with the serializer.
My main() code I'm using for testing looks like this:
SAXParser sp= SAXParserFactory.newInstance().newSAXParser();
XMLReader reader= sp.getXMLReader();
UnWrapper unwrapper= new UnWrapper();
unwrapper.setParent(reader);
Serializer serializer2= SerializerFactory.getSerializer(props);
serializer2.setOutputStream(new FileOutputStream("out.xml"));
unwrapper.setContentHandler(serializer2.asContentHandler());
unwrapper.parse(new InputSource(new FileInputStream("in.xml")));UnWrapper is a SAX event filter which is converting the XML <dtd> and <comment> elements back into the startDTD() and comment() callbacks. This in turn is based on a:
class ExtendedFilterImpl extends XMLFilterImpl
implements DeclHandler, LexicalHandler
ExtendedFilterImpl is an XMLFilterImpl work-alike which by default passes on all the
normal XMLFilterImpl events as well as Decl/Lexical events and is
designed to be overridden just like XMLFilterImpl (and is exactly
what UnWrapper is based on).
I'm pretty sure my startDTD() events are being produced my UnWrapper class, but they never appear in the serialized Output.
My exploration of the source code hasn't been too promising, the comments in ToSAXHandler.startDTD(...): // do nothing for now don't look too hopeful! But even this doesn't explain the lack of comments in the output.
I imagined I might have needed something like:
unwrapper.setContentHandler(serializer2.asContentHandler());
unwrapper.setLexicalHandler(serializer2.asLexicalHandler());but that isn't available and I couldn't see how I could easily get there from the existing code.
I was hoping that it would be possible, as I would guess that Xalan's XSLT engine would be producing comment() events for serialization? I also noticed classes like SerializationHandler extending LexicalHandler which looked hopeful.
I'm wondering if I'm fighting against the intended design, or perhaps its a small bug or small bit missing from the implementation?
If my use-case is concerning/confusing people, how about this simpler one:
Is it possible to "round-trip" an XML file by hooking up the Serializer to a
SAX parser which also uses a LexicalHandler, to report startDTD()
and comment() SAX events?
Any hints/ideas/pointers-in-the-right-direction would be much appreciated,
Thanks,
Nigel
-- Nigel Whitaker, DeltaXML.com: "Change control for XML, in XML" [EMAIL PROTECTED] http://www.deltaxml.com
