Java tutorial
//package com.java2s; public class Main { private static final String CDATA_CLOSE = "]]>"; private static final String CDATA_OPEN = "<![CDATA["; private static final int CDATA_LENGTH = CDATA_OPEN.length() + CDATA_CLOSE.length(); public static String asCdata(String data) { StringBuilder sb = new StringBuilder(data.length() + CDATA_LENGTH); sb.append(CDATA_OPEN).append(data).append(CDATA_CLOSE); return sb.toString(); } }