1 package tim.prune.save.xml;
4 * Collection of utility functions for handling XML
6 public abstract class XmlUtils
8 /** Start of Cdata sequence */
9 private static final String CDATA_START = "<![CDATA[";
10 /** End of Cdata sequence */
11 private static final String CDATA_END = "]]>";
14 * Fix the CDATA blocks in the given String to give valid xml
15 * @param inString String to modify
16 * @return fixed String
18 public static String fixCdata(String inString)
20 if (inString == null) return "";
21 if (inString.indexOf('<') < 0 && inString.indexOf('>') < 0) {
24 String result = inString;
25 // Remove cdata block at start if present
26 if (result.startsWith(CDATA_START)) {
27 result = result.substring(CDATA_START.length());
29 // Remove all instances of end block
30 result = result.replaceAll(CDATA_END, "");
31 // Now check whether cdata block is required
32 if (result.indexOf('<') < 0 && result.indexOf('>') < 0) {
35 return CDATA_START + result + CDATA_END;