Here you can find the source of escape4XML(long study_id, String xmlStr)
public static String escape4XML(long study_id, String xmlStr)
//package com.java2s; //License from project: Open Source License import java.text.CharacterIterator; import java.text.StringCharacterIterator; public class Main { public static String escape4XML(long study_id, String xmlStr) { if (xmlStr == null) return null; StringBuilder result = new StringBuilder(); StringCharacterIterator sci = new StringCharacterIterator(xmlStr); char c = sci.current(); while (c != CharacterIterator.DONE) { if (c == '<') { result.append("<"); } else if (c == '>') { result.append(">"); } else if (c == '\"') { result.append("""); } else if (c == '\'') { result.append("'"); } else if (c == '&') { result.append("&"); } else { if (!Character.isDefined(c)) { try { throw new Exception(); } catch (Exception e) { // TODO Auto-generated catch block System.err.println("study:" + study_id + " undefined charachter:" + c + " in " + xmlStr); }//from www.ja v a 2 s . com } result.append(c); } c = sci.next(); } return result.toString(); } }