Java XML Attribute from Node xmlGetAttribute(Node node, String attrname)

Here you can find the source of xmlGetAttribute(Node node, String attrname)

Description

Reads an attribut from a DOM Node.

License

Apache License

Parameter

Parameter Description
node The Node to read the attribute from.
attrname The name of the attribute to read.

Declaration

public static String xmlGetAttribute(Node node, String attrname) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

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

public class Main {
    /**//  ww w.  jav a 2  s.  c o  m
     * Reads an attribut from a DOM Node.
     * 
     * @param node
     *            The Node to read the attribute from.
     * @param attrname
     *            The name of the attribute to read.
     */
    public static String xmlGetAttribute(Node node, String attrname) {
        String theValue = null;
        if (node == null)
            return null;

        NamedNodeMap attrs = node.getAttributes();
        if (attrs != null) {
            Node attr = attrs.getNamedItem(attrname);
            if (attr != null) {
                return attr.getNodeValue();
            }
        }

        return theValue;
    }
}

Related

  1. parseAttribute(Node lnNode, String attributeName)
  2. parseAttribute(NodeList abtList)
  3. parseAttributes(Node n)
  4. parseAttributes(Node node)
  5. parseAttributesTag(Node n)
  6. xmlGetAttribute2(Node node, String attrname)