class StringUtil {

    public static String escapeXml(String value) {
        // null to null
        if (value == null)
            return null;

        // assume the resulting string will be the same
        int len = value.length();
        StringBuilder buf = new StringBuilder(len);

        for (int i = 0; i < len; i++) {
            char c = value.charAt(i);
            boolean entityFound = false;
            // is this a matching entity?
            for (int j = 0; j < XML_CHARS.length; j++) {
                // is this the matching character?
                if (c == XML_CHARS[j][0].charAt(0)) {
                    // append the entity
                    buf.append(XML_CHARS[j][1]);
                    entityFound = true;
                }
            }
            if (!entityFound) {
                buf.append(c);
            }
        }
        return buf.toString();
    }

}