Java XML Attribute Get getAttribute(Node attrNode)

Here you can find the source of getAttribute(Node attrNode)

Description

get Attribute

License

Open Source License

Declaration

public static String getAttribute(Node attrNode) 

Method Source Code

//package com.java2s;

import org.w3c.dom.Node;

public class Main {

    public static String getAttribute(Node attrNode) {

        StringBuffer value = new StringBuffer();

        if (attrNode != null && attrNode.getChildNodes().getLength() > 0) {

            int childCount = attrNode.getChildNodes().getLength();
            for (int i = 0; i < childCount; i++) {
                value.append(attrNode.getChildNodes().item(i).getNodeValue());
            }/*ww w  . jav a  2s .c  om*/
        }

        return value.toString().trim();
    }

    public static String getAttribute(Node node, String name) {

        if (!node.hasAttributes()) {
            return null;
        }

        StringBuffer value = new StringBuffer();

        Node attrNode = node.getAttributes().getNamedItem(name);
        if (attrNode != null && attrNode.getChildNodes().getLength() > 0) {

            int childCount = attrNode.getChildNodes().getLength();
            for (int i = 0; i < childCount; i++) {
                value.append(attrNode.getChildNodes().item(i).getNodeValue());
            }
        }

        return value.toString().trim();
    }
}

Related

  1. getAttribute(final Node xml, final String namespaceURI, final String localName)
  2. getAttribute(NamedNodeMap map, String name)
  3. getAttribute(NamedNodeMap namedNodeMap, String name)
  4. getAttribute(NamedNodeMap ruleAttributes, String attributeName)
  5. getAttribute(Node aNode, String attributeName)
  6. getAttribute(Node currentNode, String attributeName)
  7. getAttribute(Node element, String attName)
  8. getAttribute(Node element, String name, String dflt)
  9. getAttribute(Node iNode, String iAttributeName)