Java examples for XML:XML Encoding
Replace greek character entity names with entity names that work in HTML.
/*//from w w w .jav a 2 s. c o m * Copyright (C) 2002-2015 FlyMine * * This code may be freely distributed and modified under the * terms of the GNU Lesser General Public Licence. This should * be distributed with the code. See the LICENSE file for more * information or http://www.gnu.org/copyleft/lesser.html. * */ //package com.java2s; import java.util.HashMap; import java.util.Map; public class Main { public static void main(String[] argv) throws Exception { String value = "java2s.com"; System.out.println(fixEntityNames(value)); } private static Map<String, String> replacements = new HashMap<String, String>(); /** * Replace greek character entity names with entity names that work in HTML. * @param value input string * @return string with replacements */ public static String fixEntityNames(String value) { String retVal = value; if (retVal.indexOf('&') != -1) { for (Map.Entry<String, String> entry : replacements.entrySet()) { String orig = entry.getKey(); String replacement = entry.getValue(); retVal = retVal.replaceAll("&" + orig + ";", "&" + replacement + ";"); if (retVal.indexOf('&') == -1) { break; } } } return retVal; } }