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 List getChildElementByTagName(Element parentElement, String tagName) {
    NodeList list = parentElement.getChildNodes();
    ArrayList l = new ArrayList();
    for (int i = 0; i < list.getLength(); i++) {
        Node n = list.item(i);
        if ((n instanceof Element) && n.getNodeName().equals(tagName))
            l.add(n);/*from ww  w  .  j a v a 2 s .c o  m*/
    }
    return l;
}

From source file:Main.java

/**
 * Get the node set from parent node by the specified  name
 *
 * @param parent/* w  ww .j a v  a2  s. c om*/
 * @param name
 * @return
 */
public static Element[] getElementsByName(Element parent, String name) {
    ArrayList resList = new ArrayList();
    NodeList nl = getNodeList(parent);
    for (int i = 0; i < nl.getLength(); i++) {
        Node nd = nl.item(i);
        if (nd.getNodeName().equals(name)) {
            resList.add(nd);
        }
    }
    Element[] res = new Element[resList.size()];
    for (int i = 0; i < resList.size(); i++) {
        res[0] = (Element) resList.get(i);
    }
    return res;
}

From source file:Main.java

public static void getEntityValues(Node node, Map map) {
    if (node instanceof EntityReference) {
        map.put(node.getNodeName(), node);
    }//  ww w  . ja v a2 s .c  om
    NodeList list = node.getChildNodes();
    for (int i = 0; i < list.getLength(); i++) {
        getEntityValues(list.item(i), map);
    }
}

From source file:Main.java

private static boolean nodeNameMatch(Node node, Collection<?> desiredNames) {
    return (desiredNames.contains(node.getNodeName()) || desiredNames.contains(node.getLocalName()));
}

From source file:Main.java

public static void xmlDebug(Node n) {
    System.err.println("NodeName: '" + n.getNodeName() + "'");
    System.err.println("NodeValue: '" + n.getNodeValue() + "'");
}

From source file:Main.java

public static Node getChildNodeByName(Node node, String name) {
    if (node == null)
        return null;

    NodeList childs = node.getChildNodes();
    for (int i = 0; i < childs.getLength(); i++) {
        Node child = childs.item(i);
        if (child.getNodeName().equalsIgnoreCase(name)) {
            return child;
        }//from  w  w  w .j a va  2s  .c  om

    }
    // not found
    return null;
}

From source file:Main.java

public static String getAttributeValue(Element start, String attrName) {
    if (start.getNodeType() == Element.ELEMENT_NODE) {
        NamedNodeMap startAttr = start.getAttributes();
        for (int i = 0; i < startAttr.getLength(); i++) {
            Node attr = startAttr.item(i);
            if (attrName.equals(attr.getNodeName().trim()))
                return attr.getNodeValue().trim();
        }// ww  w  . j a  v a 2 s  . c  o m
        return null;
    } else
        return null;
}

From source file:Main.java

private static Node actualFindNode(Node node, String name) {

    String nodeName = node.getNodeName();
    nodeName = nodeName.substring((nodeName.indexOf(":") != -1 ? nodeName.indexOf(":") + 1 : 0));

    if (nodeName.equals(name)) {
        return node;
    }//from   w  w w .  j av  a  2 s  .co m
    if (node.hasChildNodes()) {
        NodeList list = node.getChildNodes();
        int size = list.getLength();

        for (int i = 0; i < size; i++) {
            Node found = actualFindNode(list.item(i), name);
            if (found != null)
                return found;
        }
    }
    return null;
}

From source file:Main.java

public static List<Element> getChildNodes(Element parent, String name) {
    List<Element> result = new ArrayList<Element>();
    NodeList childNodes = parent.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node n = childNodes.item(i);
        if (name.equals(n.getNodeName())) {
            result.add((Element) n);
        }//from  w w w.j a  v a  2s  .  c o  m
    }
    return result;
}

From source file:Main.java

/**
 * Get fisrt specified child node by tag name.
 * //w ww. j  a  v  a  2 s.c om
 * @param parent
 *          the parent node
 * @param tagName
 *          the tag name
 * @return the child node
 * @throws Exception
 *           on error
 */
public static Node getFirstChildNode(Node parent, String tagName) throws Exception {
    if (null != parent) {
        NodeList childrenList = parent.getChildNodes();
        int childrenCnt = childrenList.getLength();
        for (int i = 0; i < childrenCnt; i++) {
            Node child = childrenList.item(i);
            if (child.getNodeName().equals(tagName)) {
                return child;
            }
        }
    }
    return null;
}