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

/** Finds and returns the last child node with the given name. */
public static Element getLastChildElement(Node parent, String elemNames[]) {

    // search for node
    Node child = parent.getLastChild();
    while (child != null) {
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            for (int i = 0; i < elemNames.length; i++) {
                if (child.getNodeName().equals(elemNames[i])) {
                    return (Element) child;
                }// ww  w . jav a 2  s  .  c  om
            }
        }
        child = child.getPreviousSibling();
    }

    // not found
    return null;

}

From source file:Main.java

/** Finds and returns the first child node with the given name. */
public static Element getFirstChildElement(Node parent, String elemNames[]) {

    // search for node
    Node child = parent.getFirstChild();
    while (child != null) {
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            for (int i = 0; i < elemNames.length; i++) {
                if (child.getNodeName().equals(elemNames[i])) {
                    return (Element) child;
                }//from w w  w .j  a  va2  s. c o m
            }
        }
        child = child.getNextSibling();
    }

    // not found
    return null;

}

From source file:Main.java

/** Finds and returns the next sibling node with the given name. */
public static Element getNextSiblingElement(Node node, String elemNames[]) {

    // search for node
    Node sibling = node.getNextSibling();
    while (sibling != null) {
        if (sibling.getNodeType() == Node.ELEMENT_NODE) {
            for (int i = 0; i < elemNames.length; i++) {
                if (sibling.getNodeName().equals(elemNames[i])) {
                    return (Element) sibling;
                }/*ww  w .  java  2 s.co  m*/
            }
        }
        sibling = sibling.getNextSibling();
    }

    // not found
    return null;

}

From source file:Main.java

/** Finds and returns the last child node with the given qualified name. */
public static Element getLastChildElementNS(Node parent, String[][] elemNames) {

    // search for node
    Node child = parent.getLastChild();
    while (child != null) {
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            for (int i = 0; i < elemNames.length; i++) {
                String uri = child.getNamespaceURI();
                if (uri != null && uri.equals(elemNames[i][0])
                        && child.getLocalName().equals(elemNames[i][1])) {
                    return (Element) child;
                }//w  w w. j av a  2s .c  o m
            }
        }
        child = child.getPreviousSibling();
    }

    // not found
    return null;

}

From source file:Main.java

private static boolean checkNodeTypes(Node childNode) {
    short nodeType = childNode.getNodeType();

    if (nodeType == Node.ELEMENT_NODE) {
        cleanEmptyTextNodes(childNode); // recurse into subtree
    }/*from w w  w.j  av  a2  s .  co m*/

    if (nodeType == Node.ELEMENT_NODE || nodeType == Node.CDATA_SECTION_NODE || nodeType == Node.COMMENT_NODE) {
        return true;
    } else {
        return false;
    }
}

From source file:Main.java

/** Finds and returns the first child node with the given qualified name. */
public static Element getFirstChildElementNS(Node parent, String[][] elemNames) {

    // search for node
    Node child = parent.getFirstChild();
    while (child != null) {
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            for (int i = 0; i < elemNames.length; i++) {
                String uri = child.getNamespaceURI();
                if (uri != null && uri.equals(elemNames[i][0])
                        && child.getLocalName().equals(elemNames[i][1])) {
                    return (Element) child;
                }/*from  w  w w  . ja v a 2 s. c  o  m*/
            }
        }
        child = child.getNextSibling();
    }

    // not found
    return null;

}

From source file:Main.java

/** Finds and returns the first child element node. */
public static Element getFirstChildElement(Node parent) {

    if (parent == null)
        return null;
    // search for node
    Node child = parent.getFirstChild();
    while (child != null) {
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            return (Element) child;
        }//  w  w w .j  a  v a 2s.c o  m
        child = child.getNextSibling();
    }

    // not found
    return null;

}

From source file:Main.java

/** Finds and returns the next sibling node with the given qualified name. */
public static Element getNextSiblingElementNS(Node node, String[][] elemNames) {

    // search for node
    Node sibling = node.getNextSibling();
    while (sibling != null) {
        if (sibling.getNodeType() == Node.ELEMENT_NODE) {
            for (int i = 0; i < elemNames.length; i++) {
                String uri = sibling.getNamespaceURI();
                if (uri != null && uri.equals(elemNames[i][0])
                        && sibling.getLocalName().equals(elemNames[i][1])) {
                    return (Element) sibling;
                }//from  w  w  w. java 2 s  .  c om
            }
        }
        sibling = sibling.getNextSibling();
    }

    // not found
    return null;

}

From source file:Main.java

/** Finds and returns the last child element node. 
 *  Overload previous method for non-Xerces node impl.
 *///from   w  w w.  jav a 2  s.co  m
public static Element getLastChildElement(Node parent) {

    // search for node
    Node child = parent.getLastChild();
    while (child != null) {
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            return (Element) child;
        }
        child = child.getPreviousSibling();
    }

    // not found
    return null;

}

From source file:Main.java

public static ArrayList<String> getNodeListAttValAsStringCols(final String xPath, final Node node,
        final String[] attrNames, final String sep) throws Exception {
    ArrayList<String> retV = new ArrayList<String>();

    String locSep = " ";

    if (sep != null) {
        locSep = sep;/*from  w  ww.  j  ava  2 s  . c  om*/
    }
    int aNamesL = attrNames.length;
    if (aNamesL > 0) {

        NodeList nl = getNodesListXpathNode(xPath, node);
        int l = nl.getLength();
        Element e = null;
        String val = "";

        for (int i = 0; i < l; i++) {
            e = (Element) nl.item(i);
            if (e.getNodeType() == Node.ELEMENT_NODE) {
                StringBuilder sb = new StringBuilder();
                for (int y = 0; y < aNamesL; y++) {
                    sb.append(e.getAttribute(attrNames[y]));
                    if (y < aNamesL - 1) {
                        sb.append(locSep);
                    }
                }
                val = sb.toString();
                if (val != null && val.length() > 0) {
                    retV.add(val);
                }
            }
        }
    }
    return retV;
}