Java tutorial
//package com.java2s; import org.w3c.dom.*; public class Main { private static org.w3c.dom.Document doc; /** * Get the public id of the xml doc. * @return string of the public id. */ public static String getPublicId() { DocumentType doctype = doc.getDoctype(); if (null != doctype) { return doctype.getPublicId(); } return null; } /** * Get the type of the xml doc. * @return string of the type. */ public static String getDoctype() { DocumentType doctype = doc.getDoctype(); if (null != doctype) { return doctype.getName(); } return null; } /** * Get the name from the supplied element. * Returns the {@link Node#getLocalName() localName} of the element * if set (namespaced element), otherwise the * element's {@link Element#getTagName() tagName} is returned. * @param element The element. * @return The element name. */ public static String getName(Element element) { String name = element.getLocalName(); if (name != null) { return name; } else { return element.getTagName(); } } }