Reputation: 2038
I have a string like this:
<![CDATA[<ClinicalDocument>rest of CCD here</ClinicalDocument>]]>
I'd like to replace the escape sequences with their non-escaped characters, to end up with:
<![CDATA[<ClinicalDocument>rest of CCD here</ClinicalDocument>]]>
Upvotes: 3
Views: 1421
Reputation: 138922
Here is a non-regex solution.
String original = "something";
String[] escapes = new String[]{"<", ">"}; // add more if you need
String[] replace = new String[]{"<", ">"}; // add more if you need
String new = original;
for (int i = 0; i < escapes.length; i++) {
new = new.replaceAll(escapes[i], replace[i]);
}
Sometimes a simple loop is easier to read, understand, and code.
Upvotes: 2
Reputation: 24271
StringEscapeUtils.unescapeXml()
from commons-lang might be the thing you are looking for.
Upvotes: 6