Java tutorial
//package com.java2s; public class Main { private static final String CDATA_CLOSE = "]]>"; private static final String CDATA_CLOSE_ENCODE = "]]]]><![CDATA[>"; public static final String encodeCdata(String xml) { return xml.replace(CDATA_CLOSE, CDATA_CLOSE_ENCODE); } }