code: private static String cleanHtml(final Node node) {
          if (node instanceof Element) {
              Element element = ((Element) node);
              StringBuilder accum = new StringBuilder();
              accum.append("<").append(element.tagName());
              for (Attribute attribute: element.attributes()) {
                  if (!(attribute.getKey().startsWith("_"))) {
                      accum.append(" ");
                      accum.append(attribute.getKey());
                      accum.append("=\"");
                      accum.append(attribute.getValue());
                      accum.append('"');
                  }
              }
  
              if (element.childNodes().isEmpty() && element.tag().isEmpty()) {
                  accum.append(" />");
              } else {
                  accum.append(">");
                  for (Node child : element.childNodes())
                      accum.append(cleanHtml(child));
  
                  accum.append("</").append(element.tagName()).append(">");
              }
              return accum.toString();
          } else if (node instanceof TextNode) {
              return ((TextNode) node).getWholeText();
          } else if (node instanceof XmlDeclaration) {
  
            // HACK
            if (node.childNodes().isEmpty()) {
              return "";
            }
              return node.outerHtml();
          } else if (node instanceof Comment) {
            // HACK: elide comments for now.
            return "";
          } else if (node instanceof DataNode && node.childNodes().isEmpty()) {
          	// No child nodes are defined but we have to handle content if such exists, example
              // <script language="JavaScript">var a =  { name: "${user.name}"}</script>  
  
              String content = node.attr("data");
              if (Strings.empty(content)) {
                  return "";
              }
  
              return content;
          } else {
              return node.outerHtml();
          }
      }
docs: outerHtml from jsoup.Node, Element with suppressed _attribs