Here you can find the source of getRootTagName(String xml)
Parameter | Description |
---|---|
xml | The xml document to be searched. |
public static String getRootTagName(String xml) throws Exception
//package com.java2s; /*/*from w ww . java 2s . c o m*/ * 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(); } }