Example usage for org.w3c.dom NodeList getLength

List of usage examples for org.w3c.dom NodeList getLength

Introduction

In this page you can find the example usage for org.w3c.dom NodeList getLength.

Prototype

public int getLength();

Source Link

Document

The number of nodes in the list.

Usage

From source file:Main.java

public static void removeAll(Node node, short nodeType, String name) {
    if (node.getNodeType() == nodeType && (name == null || node.getNodeName().equals(name))) {
        node.getParentNode().removeChild(node);
    } else {/*  www .  j  a  v a2  s .  co m*/
        NodeList list = node.getChildNodes();
        for (int i = 0; i < list.getLength(); i++) {
            removeAll(list.item(i), nodeType, name);
        }
    }
}

From source file:Main.java

static String[] getNodeValue(NodeList nodes) {
    String checkIds[] = new String[nodes.getLength()];
    for (int i = 0; i < nodes.getLength(); i++) {
        Node node = nodes.item(i);
        checkIds[i] = node.getTextContent();
    }//w ww.j  a  v a 2  s  .c o m
    return checkIds;
}

From source file:Main.java

/**
 * Returns the first Element node in a NodeList
 * @param list the list to search/* ww w . ja va 2s .co  m*/
 * @return the element or null if none is found
 */
public static Element getFirstElement(NodeList list) {
    if (list.getLength() == 0) {
        return null;
    }

    Node node = list.item(0);
    while (node.getNodeType() != Node.ELEMENT_NODE) {
        if (node.getNextSibling() == null) {
            return null;
        }
        node = node.getNextSibling();
    }
    return (Element) node;
}

From source file:Main.java

public static boolean isEmpty(NodeList nodeList) {
    if (nodeList == null || nodeList.getLength() <= 0) {
        return true;
    }// w  w  w. ja  va  2  s  .c o  m
    return false;
}

From source file:Main.java

/**
 * Gets the first text value of a NodeList
 * @param nList NodeList/*w w  w .  j a  v  a  2s .  c  o m*/
 * @return first text value of a NodeList
 */
public static String getFirstTextValueFromNodeList(NodeList nList) {
    if (nList != null && nList.getLength() != 0) {
        return nList.item(0).getTextContent();
    }
    return null;
}

From source file:Main.java

public static String getText(NodeList elem) {
    if (elem.getLength() > 0 && elem.item(0).getFirstChild() != null)
        return elem.item(0).getFirstChild().getTextContent();
    return "";
}

From source file:Main.java

public static void getEntityValues(Node node, Map map) {
    if (node instanceof EntityReference) {
        map.put(node.getNodeName(), node);
    }/*from   w  w  w .j  a v  a 2  s.  c o  m*/
    NodeList list = node.getChildNodes();
    for (int i = 0; i < list.getLength(); i++) {
        getEntityValues(list.item(i), map);
    }
}

From source file:Main.java

static public Node getNode(String tagName, NodeList nodes) {
    for (int x = 0; x < nodes.getLength(); x++) {
        Node node = nodes.item(x);
        if (node.getNodeName().equalsIgnoreCase(tagName)) {
            return node;
        }/*from w  ww  .j a  v  a 2s .c o  m*/
    }

    return null;
}

From source file:Main.java

static public String getFirstValue(NodeList nodes) {
    return (nodes.getLength() == 0 ? null : getValues(nodes).get(0));
}

From source file:Main.java

@Nullable
public static Node getNode(String tagName, NodeList nodes) {
    for (int x = 0; x < nodes.getLength(); x++) {
        Node node = nodes.item(x);
        if (node.getNodeName().equalsIgnoreCase(tagName)) {
            return node;
        }/*from   w w w. j  a va2 s  .c o  m*/
    }
    return null;
}