Java tutorial
//package com.java2s; //License from project: Open Source License public class Main { public static String escapeElementContent(String xmlContent) { return escapeElementContent(xmlContent, true); } public static String escapeElementContent(String xmlContent, boolean escapeEntities) { if (xmlContent == null) return ""; String ret = xmlContent; if (escapeEntities) ret = ret.replace("&", "&"); return ret.replace("<", "<"); // There's no need to escape '>'. } }