Here you can find the source of escapeNonXmlTagSymbols(String string)
public static String escapeNonXmlTagSymbols(String string)
//package com.java2s; //License from project: Open Source License import java.text.CharacterIterator; import java.text.StringCharacterIterator; import java.util.regex.Pattern; public class Main { private static Pattern non_xml_pattern = Pattern.compile("[a-zA-Z0-9{-}{_}]"); public static String escapeNonXmlTagSymbols(String string) { StringBuffer result = new StringBuffer(); StringCharacterIterator iterator = new StringCharacterIterator(string); Character character = iterator.current(); while (character != CharacterIterator.DONE) { if (non_xml_pattern.matcher(character.toString()).matches()) result.append(character); character = iterator.next(); }/* ww w . j a v a2s. co m*/ return result.toString(); } }