Example usage for org.w3c.dom Element getElementsByTagName

List of usage examples for org.w3c.dom Element getElementsByTagName

Introduction

In this page you can find the example usage for org.w3c.dom Element getElementsByTagName.

Prototype

public NodeList getElementsByTagName(String name);

Source Link

Document

Returns a NodeList of all descendant Elements with a given tag name, in document order.

Usage

From source file:Main.java

public static Node getNodeByTagName(Element node, String name) {
    NodeList nodeList = node.getElementsByTagName(name);
    if (nodeList != null && nodeList.getLength() > 0)
        return nodeList.item(0);
    else/*from   w  w w.j  a  v  a  2s.  co m*/
        return null;
}

From source file:Main.java

public static Element getChildElement(String elementName, Element parentElement) {
    NodeList childList = parentElement.getElementsByTagName(elementName);
    if (childList == null || childList.getLength() == 0) {
        return null;
    }/*from w  w  w .j  ava 2 s .c  o  m*/

    return (Element) childList.item(0);
}

From source file:Main.java

protected static String getString(String tagName, Element rootElement) {
    NodeList list = rootElement.getElementsByTagName(tagName);
    if (list != null && list.getLength() > 0) {
        NodeList subList = list.item(0).getChildNodes();
        if (subList != null && subList.getLength() > 0) {
            return subList.item(0).getNodeValue();
        }//from  www . jav a  2s  . c o  m
    }

    return null;
}

From source file:Main.java

/**
 * Get the first child element with the given name.
 *
 * @param element The parent element//from w  w  w. j a  v  a2 s  . co  m
 * @param name The child element name
 * @return The child element or null
 */
public static Element getChild(Element element, String name) {
    return (Element) element.getElementsByTagName(name).item(0);
}

From source file:Utils.java

/**
 * Return a list of named Elements.//from  www. ja v  a 2s  .co  m
 * @param element the containing Element
 * @param name the tag name
 * @return NodeList of matching elements
 */
public static NodeList getElementList(Element element, String name) {
    return element.getElementsByTagName(name);
}

From source file:Main.java

public static Element getChildElement(String elementName, Element parentElement) {
    NodeList childList = parentElement.getElementsByTagName(elementName);
    if (childList == null || childList.getLength() == 0) {
        return null;
    }/*from www.  j a v  a2 s  . co  m*/

    Element element = (Element) childList.item(0);
    return element;
}

From source file:Main.java

public static Element getElementByTagName(Element parent, String childName) {
    NodeList nl = parent.getElementsByTagName(childName);
    if (nl.getLength() == 0)
        return null;
    return (Element) nl.item(nl.getLength() - 1);
}

From source file:Main.java

/**
 * Constructs a rgb value from given document
 * @param elem/*w  w w  .  j  a v  a 2 s .c o  m*/
 * @return
 */
public static Color getRGB(Element elem) {
    int r = Integer.parseInt(elem.getElementsByTagName(TAG_NAME_RED).item(0).getTextContent());
    int g = Integer.parseInt(elem.getElementsByTagName(TAG_NAME_GREEN).item(0).getTextContent());
    int b = Integer.parseInt(elem.getElementsByTagName(TAG_NAME_BLUE).item(0).getTextContent());
    return new Color(r, g, b);

}

From source file:Main.java

public static Element getElementFromElement(Element element, String name) {
    Element result = (Element) element.getElementsByTagName(name).item(0);
    return result;
}

From source file:Main.java

public static Vector<Element> extractElementList(Element elem, String name) {
    NodeList nl = elem.getElementsByTagName(name);
    Vector<Element> values = new Vector<Element>(nl.getLength());
    for (int n = 0; n < nl.getLength(); n++) {
        Element element = (Element) nl.item(n);
        if (element != null)
            values.addElement(element);/*from  w  ww .  ja v a2  s.  c  om*/
    }
    return values;
}