> I have a Xml dom node and I want to print it to a file. I want all the node > types to printed like element, doctype and comment nodes. > Does anyone has a idea how to print it. Is there a convenient API?
1) Most DOM implementations come with a serializer which will render a document (or a subtree) as XML syntax. Check the documentation for yours. 2) Yes, Xalan can be used as a serializer. Use the TrAX APIs, pass us a DOMSource which has been set to point to your Node, and pass us a StreamResult to tell us where to write the output. The "default identity transformation" should copy data through. HOWEVER: Note that Xalan assumes all the DOM nodes are DOM Level 2 nodes (namespace-aware); if yours isn't we may not process it correctly. Also note that the default identity tranformation has some known weak points; you may be better off using an explicit identity stylesheet, though that has its own limitations since the XPath data model used in stylesheet processing does not preserve all the details the DOM can represent.
