Java XML Attribute from Node getNodeAttributeDeep(NodeList nodelList, String nodeName, String nodeAttr)

Here you can find the source of getNodeAttributeDeep(NodeList nodelList, String nodeName, String nodeAttr)

Description

get Node Attribute Deep

License

Open Source License

Declaration

public static String getNodeAttributeDeep(NodeList nodelList, String nodeName, String nodeAttr) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    public static String getNodeAttributeDeep(NodeList nodelList, String nodeName, String nodeAttr) {
        for (int i = 0; i < nodelList.getLength(); i++) {
            Node node = nodelList.item(i);
            if (node.getNodeName().equals(nodeName)) {
                return getNodeAttribute(node, nodeAttr);
            }/*w  w w  .  j  ava 2s.co  m*/
            if (node.getChildNodes().getLength() > 0) {
                String result = getNodeAttributeDeep(node.getChildNodes(), nodeName, nodeAttr);
                if (result != null)
                    return result;
            }
        }
        return null;
    }

    public static String getNodeAttribute(Node node, String s) {
        NamedNodeMap attributes = node.getAttributes();
        for (int k = 0; k < attributes.getLength(); k++) {
            Node nodeAttr = attributes.item(k);
            if (nodeAttr.getNodeName().equals(s)) {
                return nodeAttr.getNodeValue();
            }
        }
        return null;
    }
}

Related

  1. getNodeAttribute(Node node, String name, String def)
  2. getNodeAttribute(Node node, String s)
  3. getNodeAttribute(Node QueryNode, String AttrName)
  4. getNodeAttribute(Node thisNode, String key)
  5. getNodeAttributeAsInt(Node node, String attributeName, int defaultValue)
  6. getNodeAttributes(final Node node)
  7. getNodeAttributesToString(Node node)
  8. getNodeAttributeValue(Node element, String attributeName)
  9. getNodeAttributeValue(Node node, String attribute)