public static void getXhtml(Node node, StringBuilder sb) {

    if (node.getNodeType() == Node.TEXT_NODE) {
      sb.append(lt.replace(gt.replace(node.getNodeValue(), "&gt;"), "&lt;"));
    } else if (node.getNodeType() == Node.ELEMENT_NODE) {
      Element element = (Element) node;
      sb.append("<" + node.getNodeName().toLowerCase());
      int i = 0;
      JsArray<Node> attributes = getAttributes(element);
      while (i < attributes.length()) {
        Node attribute = attributes.get(i);
        String nodeName = attribute.getNodeName();
        String nodeValue = impl.getAttributeStringValue(element, nodeName);
        sb.append(" " + nodeName.toLowerCase() + "=\""
            + (nodeValue != null ? nodeValue.replaceAll("&", "&amp;") : "") + "\"");
        i++;
      }
      if (!element.hasChildNodes()) {
        if (SELF_CLOSING_TAGS.contains(element.getTagName().toLowerCase())) {
          sb.append("/>");
        } else {
          sb.append("></" + element.getTagName().toLowerCase() + ">");
        }
      } else {
        sb.append(">");
        Node child = element.getFirstChild();
        while (child != null) {
          getXhtml(child, sb);
          child = child.getNextSibling();
        }
        sb.append("</" + element.getNodeName().toLowerCase() + ">");
      }
    }
  }