Java Utililty Methods XML Element Root

List of utility methods to do XML Element Root

Description

The list of methods to do XML Element Root are organized into topic(s).

Method

intgetRootElementPosition(String buf, Element root)
get Root Element Position
NodeList children = root.getOwnerDocument().getChildNodes();
int pos = 0;
for (int i = 0; i < children.getLength(); i++) {
    Node n = children.item(i);
    if (n != root) {
        String s = n.getNodeValue();
        if (s != null) {
            pos += s.length();
...
ElementgetRootFaceletElement(Document document)
get Root Facelet Element
Element root = document.getDocumentElement();
Element component = findComponentElement(root);
return component != null ? component : root;
ElementgetRootFromPom(File pomFile)
get Root From Pom
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(pomFile);
Element root = document.getDocumentElement();
return root;
ElementgetRootFromString(String str)
get Root From String
return getAsDocument(str).getDocumentElement();
NodegetRootNode(Document doc, String nodeName)
get Root Node
NodeList nodes = doc.getElementsByTagName(nodeName);
if (nodes == null || nodes.getLength() == 0)
    return (null);
return (nodes.item(0));
NodegetRootNode(Document document)
get Root Node
NodeList nodeList = document.getChildNodes();
return nodeList.item(0);
NodegetRootNode(final String xmlContent)
get Root Node
final Document document = parse(xmlContent);
return document.getDocumentElement();
StringgetRootTagName(String xml)
Returns root tagname
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder builder = dbf.newDocumentBuilder();
Document document = builder.parse(new InputSource(new StringReader(xml)));
return document.getDocumentElement().getTagName();