Convert org.w3c.dom.Node To String Using Java

Here is a useful method to convert an org.w3c.dom.Node object to String representation. node.toString() does not work. Well, it may give you a String but not the one that you would expect, such as a set of xml tags. What you need to use is the Transformer class.

A very important thing to note is that the transformer.setOutputProperty() must be called with OMIT_XML_DECLARATION set to yes so that the string <?xml version=”1.0″ encoding=”UTF-8″?> will not be added to the output.

Related Posts Plugin for WordPress, Blogger...

Leave a Reply

Your email address will not be published. Required fields are marked *