Java tutorial
//package com.java2s; /******************************************************************************* * Copyright (c) 2004, 2007 Boeing. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Boeing - initial API and implementation *******************************************************************************/ import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static String[] getTagDataArray(String xmlStr, String xmlRoot) { List<String> data = new ArrayList<String>(); Matcher m; m = Pattern.compile("<" + xmlRoot + ">(.*?)</" + xmlRoot + ">", Pattern.MULTILINE | Pattern.DOTALL) .matcher(xmlStr); while (m.find()) { data.add(xmlToText(m.group(1))); } return data.toArray(new String[data.size()]); } /** * Given xml strings containing xml reserved characters, replace with displayable characters > <= & gt; < <= & lt; & * <= & amp; ' <= & apos; " <= & quot; */ public static String xmlToText(String xml) { if (xml == null || xml.equals("")) { return ""; } String str = xml; str = str.replaceAll(">", ">"); str = str.replaceAll("<", "<"); str = str.replaceAll("'", "'"); str = str.replaceAll(""", "\""); str = str.replaceAll("&", "&"); return str; } }