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 { public static String getRootTag(String xmlStr) { Matcher m; m = Pattern.compile("^[\r\n \t]*<.*?>[\r\n \t]*<(.*?)>", Pattern.MULTILINE | Pattern.DOTALL) .matcher(xmlStr); if (m.find()) { return m.group(1); } return ""; } }