Java tutorial
//package com.java2s; import java.util.StringTokenizer; public class Main { public static void appendParamValues(StringBuffer params, String tagValues, String tagName) { appendParamValues(params, tagValues, tagName, null); } public static void appendParamValues(StringBuffer params, String tagValues, String tagName, String delim) { if (tagValues != null) { if (delim == null || delim.trim().length() == 0) { delim = ","; } StringTokenizer st = new StringTokenizer(tagValues.trim(), delim); while (st.hasMoreTokens()) { params.append("<" + tagName + " id=\"" + encodeStringForXml(st.nextToken().trim()) + "\"></" + tagName + ">"); } } } /** * encode the string because of the xml convertion. * * @param str * @return */ public static String encodeStringForXml(String str) { if (str == null) return str; str = str.replaceAll("\"", """); str = str.replaceAll("<", "<"); str = str.replaceAll(">", ">"); str = str.replaceAll("&", "&"); return str; } }