Java XML NodeList containsNature(NodeList nodes, String nature)

Here you can find the source of containsNature(NodeList nodes, String nature)

Description

Check whether the given nature is represented by at least one node in nodes.

License

Apache License

Parameter

Parameter Description
nodes list of nodes to be considered
nature the nature to search for

Return

true if the nature is represented by at least one node in nodes, false else

Declaration

private static boolean containsNature(NodeList nodes, String nature) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    /**/*from w w  w  . j  a  v  a  2s  .co m*/
     * Check whether the given <code>nature</code> is represented by at least one node in <code>nodes</code>.
     * 
     * @param nodes list of nodes to be considered
     * @param nature the nature to search for
     * @return <code>true</code> if the nature is represented by at least one node in <code>nodes</code>, 
     *     <code>false</code> else
     */
    private static boolean containsNature(NodeList nodes, String nature) {
        boolean contains = false;
        for (int i = 0; !contains && i < nodes.getLength(); i++) {
            contains = checkNature(nodes.item(i), nature);
        }
        return contains;
    }

    /**
     * Checks whether the text content of the given <code>node</code> matches the given <code>nature</code>.
     * 
     * @param node the node to be checked
     * @param nature the nature to be considered
     * @return <code>true</code> if the nature is represented by <code>node</code>, <code>false</code> else
     */
    private static boolean checkNature(Node node, String nature) {
        return node.getTextContent().trim().equals(nature);
    }
}

Related

  1. asList(NodeList nodeList)
  2. canonizeNodeList(NodeList nodelist)
  3. combine(final NodeList... nls)
  4. combineNodeLists(NodeList successfulReportList, NodeList failedAssertList)
  5. containsElementByValue(NodeList elements, String value)
  6. convertNodelistToSet(NodeList xpathNodeSet)
  7. convertToArray(NodeList e)
  8. convertToArray(NodeList list)
  9. convertToElementList(org.w3c.dom.NodeList _nodeList)