Java XML Attribute Get getAttributeValue(Node node, String attrName)

Here you can find the source of getAttributeValue(Node node, String attrName)

Description

Returns string value of the named attribute of the node.

License

Open Source License

Parameter

Parameter Description
node The node to extract attribute from
attrName The name of the attribute

Exception

Parameter Description
NullPointerException If <code>node</code> is <code>null</code>

Return

String value of the attribute or null

Declaration

public static String getAttributeValue(Node node, String attrName) 

Method Source Code


//package com.java2s;
/*/*from w  w  w  . j  a v a  2  s.  co  m*/
 * 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();
    }
}

Related

  1. getAttributeValue(Node node, String attributeName)
  2. getAttributeValue(Node node, String attributeName)
  3. getAttributeValue(Node node, String attributeName)
  4. getAttributeValue(Node node, String attributeName)
  5. getAttributeValue(Node node, String attributeName, int defaultValue)
  6. getAttributeValue(Node node, String attrName)
  7. getAttributeValue(Node node, String name)
  8. getAttributeValue(Node node, String name)
  9. getAttributeValue(Node node, String name)