Java XML Attribute from Node getNodeAttributeValue(Node node, String attribute)

Here you can find the source of getNodeAttributeValue(Node node, String attribute)

Description

get Node Attribute Value

License

Open Source License

Declaration

public static String getNodeAttributeValue(Node node, String attribute) 

Method Source Code

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

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

public class Main {
    public static String getNodeAttributeValue(Node node, String attribute) {
        String value = null;/*  w w w  .j  av  a  2s  . c  o  m*/
        NamedNodeMap attributes = node.getAttributes();
        /*
        for(int i = 0 ; i < attributes.getLength(); i++) {
        //System.out.println(attributes.item(i).getNodeName());
        if(attributes.item(i).getNodeName().equals("xmi.id")) {
        System.out.println(attributes.item(i).getNodeValue());
        String id = attributes.item(i).getNodeValue();
        if(id.startsWith("3ij")) {
            System.out.println("!!!!!!!!!");
        }
        }
        }
        */
        Node valueNode = attributes.getNamedItem(attribute);
        if (valueNode != null)
            value = valueNode.getNodeValue();
        return value;
    }
}

Related

  1. getNodeAttributeAsInt(Node node, String attributeName, int defaultValue)
  2. getNodeAttributeDeep(NodeList nodelList, String nodeName, String nodeAttr)
  3. getNodeAttributes(final Node node)
  4. getNodeAttributesToString(Node node)
  5. getNodeAttributeValue(Node element, String attributeName)
  6. getNodeAttributeValue(Node node, String attributeName)
  7. getNodeAttributeValue(Node node, String attributeName)
  8. getNodeAttributeValue(Node node, String attrName)
  9. getNodeAttributeValueNS(Node node, String namespaceURI, String attrName)