Example usage for org.w3c.dom Node getNodeName

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

Introduction

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

Prototype

public String getNodeName();

Source Link

Document

The name of this node, depending on its type; see the table above.

Usage

From source file:Main.java

public static Set<Node> findElementsByTag(Set<Node> nodes, String tag) {
    final Set<Node> result = new HashSet<>();

    for (Node child : nodes) {
        if (tag.equals(child.getNodeName())) {
            result.add(child);// w w  w  .ja  v  a 2 s  .  co m
        }
    }

    return result;
}

From source file:Main.java

public static Node[] getChildrenNamed(Node node, String name) {
    ArrayList v = new ArrayList();

    NodeList nList = node.getChildNodes();
    for (int i = 0; i < nList.getLength(); i++) {
        Node n = nList.item(i);
        if (n.getNodeName().equalsIgnoreCase(name)) {
            v.add(n);//w w w. j a v a 2s  .  c  o m
        }
    }

    Node[] nodeArray = new Node[v.size()];
    nodeArray = (Node[]) v.toArray(nodeArray);
    return nodeArray;
}

From source file:Main.java

/**
 * Determines whether the given JTree represents a TsSapInvoiceExternal from the COAST system
 * //from w  ww. j a  va2  s .co  m
 * @return True, if tree is a TsSapInvoiceExternal (converted from the corresponding XML file). False, if it is not.
 */
public static boolean isTsSapInvoiceListExternal(JTree tree) {
    Node root = (Node) tree.getModel().getRoot();
    return root.getNodeName().equals("com.scandlines.coast.common.payment.TsSapInvoiceListExternal");
}

From source file:Main.java

public static Element findChildElement(Element parent, String name) {
    Element result = null;/*from  ww  w  . j av a 2 s  . c o m*/
    NodeList nodes = parent.getChildNodes();

    for (int i = 0; i < nodes.getLength(); i++) {
        Node node = nodes.item(i);

        if (node.getNodeName().equals(name)) {
            result = (Element) node;
            break;
        }
    }

    return result;
}

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;
            }/* w w w. j av a 2 s  .co m*/
        }
    }

    return null;
}

From source file:Main.java

/**
 * Returns the child of the given node which has the specified name
 * If no such node exists, returns null// w  w  w.jav  a2 s. c  o m
 */
public static Node findChild(Node parent, String name) {
    // Iterate through the collection of children
    NodeList nodes = parent.getChildNodes();
    for (int a = 0; a != nodes.getLength(); ++a) {
        Node node = nodes.item(a);
        if (node.getNodeName().equals(name)) {
            // This is the one
            return node;
        }
    }

    // No such node
    return null;
}

From source file:Main.java

public static List<? extends Node> get_childs(Node parent, String child_name) {
    List<Node> result = new LinkedList<Node>();
    NodeList children = parent.getChildNodes();
    for (int i = 0; i < children.getLength(); ++i) {
        Node child = children.item(i);
        if (child.getNodeName().equals(child_name))
            result.add(child);/*from ww  w  .j ava  2  s.  c om*/
    }
    return result;
}

From source file:Main.java

public static boolean hasChild(Node xml, String name) {
    NodeList nl = xml.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++) {
        Node n = nl.item(i);
        if (name.equalsIgnoreCase(n.getNodeName()))
            return true;
    }/*from w  w  w  .j  a  v  a  2 s.c om*/
    return false;
}

From source file:Main.java

private static HashMap<String, String> getValoresNodo(Node nodo) {
    HashMap<String, String> valores = new HashMap<String, String>();
    NodeList listaNodo = nodo.getChildNodes();
    for (int i = 0; i < listaNodo.getLength(); i++) {
        Node n = listaNodo.item(i);
        valores.put(n.getNodeName(), getValorNodo(n));
    }//w w w  .  j  ava2 s . c om
    return valores;
}

From source file:Main.java

/**
 * Fetch node using its name/*w  ww  . j a  v  a2  s . c  o m*/
 * 
 * @param node
 * @param name
 * @return
 */
public static Node fetchByName(Node node, String name) {
    final NodeList list = node.getChildNodes();
    for (int i = 0; i < list.getLength(); i++) {
        final Node child = list.item(i);
        if (child.getNodeName().equals(name)) {
            return child;
        }
    }
    return null;
}