Java tutorial
//package com.java2s; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; public class Main { static Integer getAttributeValueAsInt(final Node node, final String attributeName) { if (node == null || attributeName == null) { return null; } try { return Integer.parseInt(getAttributeValue(node, attributeName)); } catch (NumberFormatException e) { return null; } } static String getAttributeValue(final Node node, final String attributeName) { if (node == null || attributeName == null) { return null; } final NamedNodeMap attrMap = node.getAttributes(); final Node attrNode = attrMap.getNamedItem(attributeName); if (attrNode != null) { return attrNode.getNodeValue(); } return null; } static String getNodeValue(final Node node) { if (node != null && node.getFirstChild() != null && node.getFirstChild().getNodeValue() != null) { return node.getFirstChild().getNodeValue().trim(); } return null; } }