Java tutorial
//package com.java2s; /* * Copyright (C) 2016 Alexander Vasilevsky * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import org.w3c.dom.Node; public class Main { /** * Returns string value of the named attribute of the node. * Returns <code>null</code> if such attribute does not exist. * * @param node The node to extract attribute from * @param attrName The name of the attribute * * @return String value of the attribute or <code>null</code> * * @throws NullPointerException If <code>node</code> is <code>null</code> */ public static String getAttributeValue(Node node, String attrName) { Node attr = node.getAttributes().getNamedItem(attrName); return attr == null ? null : attr.getNodeValue(); } }