Java XML Attribute Read getNullableAttribute(final Element node, final String attributeName)

Here you can find the source of getNullableAttribute(final Element node, final String attributeName)

Description

Get the attribute value under the specified name from the given element.

License

Open Source License

Parameter

Parameter Description
node element to retrieve the attribute value from
attributeName name of the targeted attribute

Return

the attribute's value (or null if no such attribute exists)

Declaration

public static String getNullableAttribute(final Element node, final String attributeName) 

Method Source Code

//package com.java2s;
/*/*from www. jav a2s  . c o  m*/
   Copyright (C) 2016 HermeneutiX.org
    
   This file is part of SciToS.
    
   SciToS 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.
    
   SciToS 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 SciToS. If not, see <http://www.gnu.org/licenses/>.
 */

import org.w3c.dom.Element;

public class Main {
    /**
     * Get the attribute value under the specified name from the given element.
     *
     * @param node
     *            element to retrieve the attribute value from
     * @param attributeName
     *            name of the targeted attribute
     * @return the attribute's value (or {@code null} if no such attribute exists)
     */
    public static String getNullableAttribute(final Element node, final String attributeName) {
        if (node.hasAttribute(attributeName)) {
            return node.getAttribute(attributeName);
        }
        return null;
    }
}

Related

  1. getLongAttribute(String name, Element el)
  2. getNameAttribute(final Node aNode)
  3. getNamedAttribute(final Node aNode, final String attributeName)
  4. getNewAttribute(Element element, String name)
  5. getNSPrefixFromNSAttr(Attr a)
  6. getNullSafe(NamedNodeMap attr, String key)
  7. getOptionalAttribute(Element elt, String name)
  8. getOptionalAttributeValue(NamedNodeMap attrs, String name)
  9. readAttribute(Node element, String attributeName)