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.regex.Matcher; import java.util.regex.Pattern; public class Main { /** * Parse <xmlRoot name="this.is.name" value="this.is.value"> and return name, value * * @param xmlRoot xml tag name * @param xmlStr string containing xml * @return String[]{name, value} */ public static String[] getNameValue(String xmlRoot, String xmlStr) { String[] strs = new String[] { "", "" }; Matcher m; m = Pattern .compile("<" + xmlRoot + " name=\"(.*?)\" value=\"(.*?)\" />", Pattern.MULTILINE | Pattern.DOTALL) .matcher(xmlStr); if (m.find()) { strs[0] = m.group(1); strs[1] = m.group(2); } return strs; } }