Encode a string
if(xmlString == null) {
return "";
}
char[] characters = xmlString.toCharArray();
StringBuffer out = null;
char character;
for (int i = 0; i < characters.length; i++) {
character = characters[i];
switch (character) {
// we don't care about single quotes since axis will
// use double quotes anyway
case '&":
if (out == null) {
out = getInitialByteArray(xmlString, i);
}
out.append(AMP);
break;
case '"":
if (out == null) {
out = getInitialByteArray(xmlString, i);
}
out.append(QUOTE);
break;
case '<":
if (out == null) {
out = getInitialByteArray(xmlString, i);
}
out.append(LESS);
break;
case '>":
if (out == null) {
out = getInitialByteArray(xmlString, i);
}
out.append(GREATER);
break;
case '\n":
if (out == null) {
out = getInitialByteArray(xmlString, i);
}
out.append(LF);
break;
case '\r":
if (out == null) {
out = getInitialByteArray(xmlString, i);
}
out.append(CR);
break;
case '\t":
if (out == null) {
out = getInitialByteArray(xmlString, i);
}
out.append(TAB);
break;
default:
if (character < 0x20) {
throw new IllegalArgumentException(Messages.getMessage("invalidXmlCharacter00", Integer.toHexString(character), xmlString.substring(0, i)));
} else {
if (out != null) {
out.append(character);
}
}
break;
}
}
if (out == null) {
return xmlString;
}
return out.toString();