Example usage for org.w3c.dom Node ELEMENT_NODE

List of usage examples for org.w3c.dom Node ELEMENT_NODE

Introduction

In this page you can find the example usage for org.w3c.dom Node ELEMENT_NODE.

Prototype

short ELEMENT_NODE

To view the source code for org.w3c.dom Node ELEMENT_NODE.

Click Source Link

Document

The node is an Element.

Usage

From source file:Main.java

public static Node getChildNode(Node node, String nodeName) {
    if (node.getNodeType() == Node.ELEMENT_NODE) {

        NodeList nodeList = node.getChildNodes();
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node n = nodeList.item(i);
            if (n.getNodeName().equals(nodeName)) {
                return n;
            }/*from  w  w w  .  j a  v  a2s  . c o m*/
        }
    }

    return null;
}

From source file:Main.java

public static Element getNextSiblingElementNode(Node node) {
    Node nextNode = node.getNextSibling();
    while (nextNode.getNodeType() != Node.ELEMENT_NODE) {
        nextNode = nextNode.getNextSibling();
    }//w  w  w .  j  a  va  2 s  .  c  o m

    return (Element) nextNode;
}

From source file:Main.java

public static Node findChild(Node node, String chName) {
    for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
        if (child.getNodeType() == Node.ELEMENT_NODE && child.getNodeName().equals(chName)) {
            return child;
        }// w  w w  .j  a v  a2 s. c om
    }
    return null;
}

From source file:Utils.java

public static Element getFirstChild(Element e, String local) {
    for (Node n = e.getFirstChild(); n != null; n = n.getNextSibling()) {
        if (n.getNodeType() == Node.ELEMENT_NODE) {
            Element c = (Element) n;
            if (c.getLocalName().equals(local))
                return c;
        }/* w  w  w.  ja v a 2 s.co m*/
    }
    return null;
}

From source file:Main.java

public static Node getChildNodeOf(Node node, String tagName) {
    for (Node temp = node.getFirstChild(); temp != null; temp = temp.getNextSibling())
        if (temp.getNodeType() == Node.ELEMENT_NODE && tagName.equals(temp.getNodeName())) {
            return temp;
        }//from  w  w  w  .ja  v  a  2 s.c o m
    return null;
}

From source file:Main.java

public static Element getNextElement(Element el) {
    Node node = el.getNextSibling();
    while (node != null) {
        if (node.getNodeType() == Node.ELEMENT_NODE)
            return (Element) node;
        node = node.getNextSibling();/*from   ww  w  .j av a2  s  .c  om*/
    }
    return null;
}

From source file:Main.java

public static Node getNode(Node node, String nodeName) {
    if (node.getNodeType() == Node.ELEMENT_NODE) {

        Element el = (Element) node;
        NodeList nodeList = el.getElementsByTagName(nodeName);
        if (nodeList.getLength() > 0) {
            return nodeList.item(0);
        }/*  ww  w  . j  ava2 s.c o m*/

    }

    return null;
}

From source file:Main.java

public static Element getLastChild(Element e) {
    if (e == null)
        return null;
    Node n = e.getLastChild();//www  . j a v  a 2 s .com
    while (n != null && n.getNodeType() != Node.ELEMENT_NODE)
        n = n.getPreviousSibling();
    return (Element) n;
}

From source file:Main.java

public static Element getNextChildElement(Node node) {
    Node n = node.getFirstChild();
    while (n != null && n.getNodeType() != Node.ELEMENT_NODE) {
        n = n.getNextSibling();//from   w  w w . j a  v a  2  s.  c  o m
    }
    return (Element) n;
}

From source file:Main.java

public static String getTagValue(Node node, String name) {

    if (node.getNodeType() == Node.ELEMENT_NODE) {

        Element el = (Element) node;
        NodeList nodeList = el.getElementsByTagName(name);
        if (nodeList.getLength() > 0) {
            el = (Element) nodeList.item(0);
            nodeList = el.getChildNodes();

            if (nodeList.getLength() > 0) {
                return ((Node) nodeList.item(0)).getNodeValue();
            }/*from ww w  .j  a v  a 2 s .co m*/
        }

    }
    return "";
}