Java tutorial
//package com.java2s; /* infoScoop OpenSource * Copyright (C) 2010 Beacon IT Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License version 3 * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0-standalone.html>. */ public class Main { /** * convert the reference of the numerical value letter into ths substance. * @param xml * @return */ public static String resolveNumEntities(String xml) { StringBuffer strb = new StringBuffer(xml); int index; int index2 = 0; int index3 = 0; while ((index = strb.toString().indexOf("&#", index2)) != -1) { index2 = strb.toString().indexOf(';', index + 1); index3 = strb.toString().indexOf("&#", index + 1); if (index2 == -1) { break; } else if (index3 != -1 && index2 > index3) { //We pass the entity description that is not right. index2 = index3; } else { try { char numericChar = (char) Integer.parseInt(strb.substring(index + 2, index2)); String numericStr = String.valueOf(numericChar); strb.replace(index, index2 + 1, numericStr); index2 = index + numericStr.length(); } catch (NumberFormatException e) { //We pass reference of the numerical value letter that is not right. } } } return strb.toString(); } }