public static void replaceControlCharacters(Node node, char replacement) {
        String value = node.getNodeValue();
        if (value != null) {
            boolean modified = false;

            byte[] bytes = value.getBytes();
            for (int b = 0; b < bytes.length; b++) {
                if (!isRegularChar(bytes[b])) {
                    bytes[b] = (byte) replacement;
                    modified = true;
                }
            }
            if (modified) node.setNodeValue(new String(bytes));
        }

        NamedNodeMap attrList = node.getAttributes();
        for (int a = 0; (attrList != null) && (a < attrList.getLength()); a++) {
            replaceControlCharacters(attrList.item(a), replacement);
        }

        NodeList childNodeList = node.getChildNodes();
        for (int c = 0; (childNodeList != null) && (c < childNodeList.getLength()); c++) {
            replaceControlCharacters(childNodeList.item(c), replacement);
        }
    }