I have written a method to check my XML strings for &.
I need to modify the method to include the following:
<
<
>
>
\
&guot
&
&
\
&apos
Here is the method
private String xmlEscape(String s) {
try {
return s.replaceAll("&(?!amp;)", "&");
}
catch (PatternSyntaxException pse) {
return s;
}
} // end xmlEscape()
Here is the way I am using it
sb.append(" <Host>" + xmlEscape(url.getHost()) + "</Host>\n");
How can I modify my method to incorporate the rest of the symbols?
EDIT
I think I must not have phrase the question correctly.
In the xmlEscape()
method I am wanting to check the string for the following chars
<
>
'
"
&
, if they are found I want to replace the found char with the correct char.
Example: if there is a char &
the char would be replaced with &
; in the string.
Can you do something as simple as
try {
s.replaceAll("&(?!amp;)", "&");
s.replaceAll("<", "<");
s.replaceAll(">", ">");
s.replaceAll("'", "'");
s.replaceAll("\"", """);
return s;
}
catch (PatternSyntaxException pse) {
return s;
}