get Attribute Int from Node by attribute name - Java XML

Java examples for XML:XML Attribute

Description

get Attribute Int from Node by attribute name

Demo Code


//package com.java2s;
import org.w3c.dom.Node;

public class Main {
    public static int getAttributeInt(Node node, String name) {
        return Integer.parseInt(getAttribute(node, name));
    }//from   w w w.ja  va2  s  .  c  o  m

    public static String getAttribute(Node node, String name) {
        if (node == null) {
            return null;
        }

        Node val = node.getAttributes().getNamedItem(name);

        if (val == null) {
            return null;
        }

        return val.getNodeValue();
    }
}

Related Tutorials