Java XML Attribute Get getAttributeValue(String attributeName, Node xmlNode)

Here you can find the source of getAttributeValue(String attributeName, Node xmlNode)

Description

get Attribute Value

License

Open Source License

Declaration

public static String getAttributeValue(String attributeName, Node xmlNode) 

Method Source Code

//package com.java2s;
/**//from   w  w w  .  j av  a2 s.  c om
 Authors:
    
 Yahor Paulavets (paulavets.pride@gmail.com)
    
 This file is part of Gobrotium project (https://github.com/a-a-a-CBEI-I-IEE-M9ICO/GoBrotium.git)
    
 Gobrotium project 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.
    
 Gobrotium 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 Gobrotium project.  If not, see <http://www.gnu.org/licenses/>.
 */

import org.w3c.dom.Node;

public class Main {
    public static String getAttributeValue(String attributeName, Node xmlNode) {
        if (xmlNode == null)
            return null;

        if (xmlNode.getAttributes() == null)
            return null;

        if (xmlNode.getAttributes().getLength() == 0)
            return null;

        Node n = xmlNode.getAttributes().getNamedItem(attributeName);

        if (n == null)
            return null;

        return n.getTextContent();
    }
}

Related

  1. getAttributeValue(Node sNode, String attribName)
  2. getAttributeValue(Node sNode, String attribName)
  3. getAttributeValue(NodeList elements, String attributeName)
  4. getAttributeValue(StartElement element, String namespaceURI, String localPart)
  5. getAttributeValue(StartElement startElement, String attributeName)
  6. getAttributeValueAsBoolean(Attr attribute)
  7. getAttributeValueAsBoolean(Element el, String attrName)
  8. getAttributeValueAsDouble(Node node, String attributeName)
  9. getAttributeValueAsInteger(Node node, String attributeName, Integer defaultValue)