Java XML Element Find findComponentElement(Element root)

Here you can find the source of findComponentElement(Element root)

Description

find Component Element

License

Open Source License

Declaration

public static Element findComponentElement(Element root) 

Method Source Code


//package com.java2s;

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    public static final String TAG_COMPOSITION = "composition";
    public static final String TAG_COMPONENT = "component";

    public static Element findComponentElement(Element root) {
        if (root == null) {
            return null;
        }/*www  .  j a va  2 s  . c o  m*/
        NodeList children = root.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            Node child = children.item(i);
            if (child.getNodeType() == Node.ELEMENT_NODE) {
                Element trimmedElement = findComponentElement((Element) child);
                if (trimmedElement != null)
                    return trimmedElement;
            }
        }
        if (TAG_COMPOSITION.equalsIgnoreCase(root.getLocalName())
                || TAG_COMPONENT.equalsIgnoreCase(root.getLocalName())) {
            return root;
        }
        return null;
    }
}

Related

  1. findAllElementsByTagName(Element elem, String tagName)
  2. findAllElementsByTagNameNS(Element el, String nameSpaceURI, String localName, List elementList)
  3. findComponentElement(Element root)
  4. findElement(Element element, String elementName)
  5. findElement(Element element, String name)
  6. findElement(Element root, String localName, String namespace)