Here you can find the source of getAttributeValue(Element element, String attrName)
Parameter | Description |
---|---|
element | a parameter |
attrName | a parameter |
public static String getAttributeValue(Element element, String attrName)
//package com.java2s; /**// ww w. jav a2 s . c o m * * This file is part of SavoyCraft. * * SavoyCraft is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your * option) any later version. * * SavoyCraft 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 Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with SavoyCraft. If not, see <http://www.gnu.org/licenses/>. * */ import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; public class Main { /** * TODO: Case sensitive? * * @param element * @param attrName * @return null if not found */ public static String getAttributeValue(Element element, String attrName) { NamedNodeMap attributes = element.getAttributes(); Node attribute = attributes.getNamedItem(attrName); if (attribute == null) { return null; } else { return attribute.getNodeValue(); } } /** * As getAttributeValue, except that if there is no attribute with the given * name, this method returns defaultValue instead. * * @param element * @param attrName * @param defaultValue * @return */ public static String getAttributeValue(Element element, String attrName, String defaultValue) { String attrValue = getAttributeValue(element, attrName); if (attrValue == null) { return defaultValue; } else { return attrValue; } } }