Java tutorial
//package com.java2s; import org.w3c.dom.Node; public class Main { public static String getString(Node aNode, String attr) { return getString(aNode, attr, null); } public static String getString(Node aNode, String attr, String aDefault) { if (aNode.getAttributes().getNamedItem(attr) != null) { String docText = aNode.getAttributes().getNamedItem(attr).getNodeValue(); return docText; } else { return aDefault; } } }