Java tutorial
//package com.java2s; /* * The following methods come from a library written by Tom Fennelly. * Here was the header of the licence. */ import java.io.StringReader; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.*; import org.xml.sax.InputSource; public class Main { /** * Returns root tagname * * @param xml The xml document to be searched. * @return String result. */ public static String getRootTagName(String xml) throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); DocumentBuilder builder = dbf.newDocumentBuilder(); Document document = builder.parse(new InputSource(new StringReader(xml))); return document.getDocumentElement().getTagName(); } }