get Attr Of Name from Node - Java XML

Java examples for XML:XML Attribute

Description

get Attr Of Name from Node

Demo Code


//package com.java2s;

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

public class Main {
    public static String getAttrOfName(Node node, String string) {
        NamedNodeMap attributes = node.getAttributes();
        Node namedItem = attributes.getNamedItem(string);
        if (namedItem == null) {
            return null;
        }/* w  w w. java  2  s.c o  m*/
        return namedItem.getNodeValue();
    }
}

Related Tutorials