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 String getNodeContent(String NodeRawname, Element element) {
    Node tmpNode = element.getElementsByTagName(NodeRawname).item(0);
    if (tmpNode != null)
        return tmpNode.getTextContent().trim();
    else/* www.j  a v  a 2  s.  c om*/
        return null;
}

From source file:Main.java

public static NodeList getChildElements(Element parentElement, String childName) {
    NodeList list = parentElement.getElementsByTagName(childName);
    return list;/*from   ww  w. j av a 2 s .c om*/
}

From source file:Main.java

public static String getSubElement(Element element, String subTagName, int itemId) {
    return element.getElementsByTagName(subTagName).item(itemId).getTextContent();
}

From source file:Main.java

/**
 * Gets the value of the first child element of parent
 * /*from   w w  w.  java2s .c  om*/
 * @param childName
 * @param parent
 * @return
 */
public static String getFirstChildValue(String childName, Element parent) {
    return getElementValue(parent.getElementsByTagName(childName).item(0));
}

From source file:Main.java

public static String getFirstElementText(Element parent, String tag) {
    NodeList nl = parent.getElementsByTagName(tag);
    if (nl.getLength() > 0) {
        return ((Element) nl.item(0)).getTextContent();
    }/*from ww w.jav  a  2 s  . c o  m*/
    return null;
}

From source file:Main.java

public static Element getFirstChild(Element parent, String name) {
    NodeList list = parent.getElementsByTagName(name);
    for (int i = 0; i < list.getLength(); i++) {
        Node child = list.item(i);
        if (child.getNodeType() == 1)
            return (Element) child;
    }//from  w  w w .  j  ava  2s . co  m

    return null;
}

From source file:Main.java

public static String tryToGetTextContent(Element element, String tag) {
    if (element.getElementsByTagName(tag).getLength() > 0) {
        return element.getElementsByTagName(tag).item(0).getTextContent();
    } else {/*from  w  ww .  java2 s  . c  o m*/
        return "";
    }
}

From source file:Main.java

public static List<Element> getChildsWithName(Element root, String name) {
    NodeList childNodes = root.getElementsByTagName(name);
    List<Element> elementList = new LinkedList<Element>();
    for (int i = 0; i < childNodes.getLength(); ++i) {
        elementList.add((Element) childNodes.item(i));
    }//  w  w w .  jav a 2 s  . c o m
    return elementList;
}

From source file:Main.java

public static Element getFirstChild(Element tag, String childTagName) {
    NodeList nodes = tag.getElementsByTagName(childTagName);
    if (nodes == null || nodes.getLength() == 0) {
        return null;
    }/*from w  w w .j  a  v  a 2s.  c o  m*/

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

From source file:Main.java

public static String getStringValueForXMLTag(Element xmlElement, String key) {
    NodeList nl = xmlElement.getElementsByTagName(key);
    if (nl.getLength() > 0) {
        Node node = nl.item(0).getFirstChild();
        if (node != null) {
            String output = node.getNodeValue().trim();
            return output;
        }/*from www .ja  v a 2 s .c  om*/
    }
    return "";
}