Java tutorial
//package com.java2s; import org.w3c.dom.Node; public class Main { public static Integer getAttributeValueAsInt(Node node, String str) { Integer num = null; if (!(node == null || str == null)) { try { num = Integer.valueOf(Integer.parseInt(getAttributeValue(node, str))); } catch (NumberFormatException e) { } } return num; } public static String getAttributeValue(Node node, String str) { if (node == null || str == null) { return null; } Node namedItem = node.getAttributes().getNamedItem(str); return namedItem != null ? namedItem.getNodeValue() : null; } public static String getNodeValue(Node node) { return (node == null || node.getFirstChild() == null || node.getFirstChild().getNodeValue() == null) ? null : node.getFirstChild().getNodeValue().trim(); } }