private static void nodeToText(StringBuilder sb, NodeList nodeList)
    {
        for (int i = 0; i < nodeList.getLength(); i++)
        {
            Node node = nodeList.item(i);
            
            if (node.getNodeType() == Node.TEXT_NODE)
            {
                sb.append(node.getTextContent());
            }
            else
            {
                if (node.hasChildNodes())
                {
                    sb.append("<" + node.getNodeName());
                    appendAttributes(sb, node);
                    sb.append(">");
                    
                    nodeToText(sb, node.getChildNodes());
                    
                    sb.append("</" + node.getNodeName() + ">");
                }
                else
                {
                    sb.append("<" + node.getNodeName());
                    appendAttributes(sb, node);
                    sb.append("/>");
                }
            }
        }
    }