Java examples for XML:XML String Escape
Clean up HTML so it doesn't break XML
//package com.java2s; public class Main { public static void main(String[] argv) throws Exception { String in = "java2s.com"; System.out.println(cleanup(in)); }/*from w w w . j av a2s .c o m*/ /** * Clean up HTML so it doesn't break XML * @param in * @return */ static String cleanup(String in) { String out = in.replaceAll("<!\\[CDATA\\[", ""); out = out.replaceAll("\\]\\]>", ""); out = out.replaceAll("&(?!amp;)", "&"); out = out.replaceAll("<br>", "<br />"); out = out.replaceAll("<p>\\s*?</li>", "</p>\n</li>"); return out; } }