code: public static String node2String(final Node node, boolean prettyPrint, String encoding) throws UnsupportedEncodingException 
     {
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        new DOMWriter(new PrintWriter(baos), encoding).setPrettyprint(prettyPrint).print(node);
        return baos.toString(encoding);
     }
docs: Converts XML node in specified pretty mode and encoding to string.
  
  @param node XML document or element
  @param prettyPrint whether XML have to be pretty formated
  @param encoding to use
  @return XML string
  @throws UnsupportedEncodingException