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 boolean isValidNode(Node node, String name) {
    return node.getNodeName().equals(name);
}

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 ww  w  .  j  a v  a  2  s.c o m
    }

    return null;
}

From source file:Main.java

public static Color toColor(Node n) {
    if (!n.getNodeName().equals("color")) {
        throw new IllegalArgumentException(n.getNodeName());
    }/* w  ww .j a  v a2s .c o  m*/
    NamedNodeMap map = n.getAttributes();
    String s = map.getNamedItem("name").getNodeValue();
    if (s.equals("white")) {
        return Color.WHITE;
    } else if (s.equals("green")) {
        return Color.GREEN;
    } else if (s.equals("pink")) {
        return Color.PINK;
    } else if (s.equals("cyan")) {
        return Color.CYAN;
    } else if (s.equals("yellow")) {
        return Color.YELLOW;
    } else {
        return Color.WHITE;
    }
}

From source file:Main.java

public static List<Node> filterNodesByTag(NodeList nodes, String tagName) {
    ArrayList<Node> result = new ArrayList<>();
    for (int i = 0; i < nodes.getLength(); i++) {
        Node node = nodes.item(i);
        if (node.getNodeName().equals(tagName)) {
            result.add(node);//from   w w w. j a  v a  2s.c om
        }
    }
    return result;
}

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  ww  .j a v  a 2  s  .c om*/
    }
    return null;
}

From source file:Main.java

public static Node get_child(Node parent, String child_name) {
    NodeList children = parent.getChildNodes();
    for (int i = 0; i < children.getLength(); ++i) {
        Node child = children.item(i);
        if (child.getNodeName().equals(child_name))
            return child;
    }//from  w w  w  .ja va2s  .  c  om
    return null;
}

From source file:Main.java

public static String getAttribute(Node node, String name) {
    NamedNodeMap attr = node.getAttributes();
    for (int n = 0; n < attr.getLength(); n++) {
        Node attribute = attr.item(n);
        if (attribute.getNodeName().equals(name))
            return attribute.getNodeValue();
    }// w ww  . jav  a2  s .c o  m
    return "";
}

From source file:Main.java

public static Node getChildNode(String name, Node node) {
    if (node == null) {
        return null;
    }//  w w w. j a va 2s  . co  m
    NodeList list = node.getChildNodes();
    for (int i = 0; i < list.getLength(); i++) {
        Node no = list.item(i);
        if (no.getNodeName().equalsIgnoreCase(name)) {
            return no;
        }
    }
    return null;
}

From source file:Main.java

public static List<Node> getNodes(String tagName, NodeList nodes) {
    List<Node> matches = new ArrayList<Node>();
    for (int x = 0; x < nodes.getLength(); x++) {
        Node node = nodes.item(x);
        if (node.getNodeName().equalsIgnoreCase(tagName)) {
            matches.add(node);/*from   w  w  w  .j a va  2s  . c  o m*/
        }
    }
    return matches;
}

From source file:Main.java

public static void removeElement(Element parent, String tagName) {
    logger.debug("remove " + parent.getNodeName() + "'s children by tagName " + tagName + " begin...");
    NodeList nl = parent.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++) {
        Node nd = nl.item(i);
        if (nd.getNodeName().equals(tagName)) {
            parent.removeChild(nd);/*from   w  w  w. j  a  v a  2s. c o  m*/
            logger.debug("remove child '" + nd + "' success.");
        }
    }
    logger.debug("remove " + parent.getNodeName() + "'s children by tagName " + tagName + " end.");
}