public String serializeToString(Element root) {
        StringBuilder sb = new StringBuilder("<");
        sb.append(root.getTag());

        String val;
        for (String attName : root.attributeNames()) {
            val = root.getAttribute(attName);
            sb.append(String.format(ATTRIBUTE_FMT, attName, val));
        }

        if (root.hasText() || root.hasChildren()) {
            sb.append(">");
        } else {
            sb.append(" />");
        }

        if (root.hasText()) {
            sb.append(root.getText());
        }

        for (Element child : root.children()) {
            sb.append(serializeToString(child));
        }

        if (root.hasText() || root.hasChildren()) {
            sb.append(String.format("</%s>", root.getTag()));
        }

        return sb.toString();
    }