public static String escapeXmlChars(String str) {
String output = str;
StringTuple[] arrStrTuple = {
new StringTuple(Constants.ampStr, Constants.ampReplaceStr),
new StringTuple(Constants.lessThanStr,
Constants.lessThanReplaceStr),
new StringTuple(Constants.greaterThanStr,
Constants.greaterThanReplaceStr) };
for (int i = 0; i < arrStrTuple.length; i++) {
StringTuple strTuple = arrStrTuple[i];
// Compile regular expression
Pattern pattern = Pattern.compile(strTuple.getFirstElementString());
// Replace all instances of the pattern
Matcher matcher = pattern.matcher(output);
output = matcher.replaceAll(strTuple.getSecondElementString());
}
return output;
}