Strip CDATA : CDATA « XML « Java






Strip CDATA

 


public class Utils {

  public static String stripCDATA(String s) {
    s = s.trim();
    if (s.startsWith("<![CDATA[")) {
      s = s.substring(9);
      int i = s.indexOf("]]&gt;");
      if (i == -1) {
        throw new IllegalStateException(
            "argument starts with <![CDATA[ but cannot find pairing ]]&gt;");
      }
      s = s.substring(0, i);
    }
    return s;
  }

}

   
  








Related examples in the same category

1.Set Data to Character Data
2.Get substring from CharacterData
3.Append and insert data to CharacterData
4.Delete data from CharacterData
5.Replace Data in CharacterData
6.Converting CDATA Nodes into Text Nodes While Parsing an XML File
7.Get character data (CDATA) from xml document
8.Escaping CDATA sections.