Java XML Escape escapeNonXmlTagSymbols(String string)

Here you can find the source of escapeNonXmlTagSymbols(String string)

Description

escape Non Xml Tag Symbols

License

Open Source License

Declaration

public static String escapeNonXmlTagSymbols(String string) 

Method Source Code

//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();
    }
}

Related

  1. escape4XML(long study_id, String xmlStr)
  2. escapeXML(String s)