Java tutorial
//package com.java2s; public class Main { public static String getAttribute(String attribute, String text) { return getAttribute(attribute, text, 0); } public static String getAttribute(String attribute, String text, int idx) { int close = text.indexOf(">", idx); int attrIdx = text.indexOf(attribute + "=\"", idx); if (attrIdx == -1) { return null; } if (attrIdx > close) { return null; } int attrStartIdx = attrIdx + attribute.length() + 2; int attrCloseIdx = text.indexOf("\"", attrStartIdx); if (attrCloseIdx > close) { return null; } return unescapeXml(text.substring(attrStartIdx, attrCloseIdx)); } public static String unescapeXml(String str) { str = str.replaceAll("&", "&"); str = str.replaceAll("<", "<"); str = str.replaceAll(">", ">"); str = str.replaceAll(""", "\""); str = str.replaceAll("'", "'"); return str; } }