Java tutorial
//package com.java2s; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; public class Main { /** * Retrieves the value for a xml Node attribute or fails if not found. * * @param <T> the exception type to throw * @param node The Node to fetch the value from. * @param name The attribute name. * @param e an Exception instance * @return the attribute value * @throws T */ public static <T extends Exception> String getNodeAttributeOrFail(Node node, String name, T e) throws T { NamedNodeMap attributes = node.getAttributes(); Node valueNode = attributes.getNamedItem(name); if (valueNode == null) throw e; return valueNode.getNodeValue(); } }