Java XML Attribute Get getAttribute(Node node, String name, String defVal)

Here you can find the source of getAttribute(Node node, String name, String defVal)

Description

Returns an attribute of the specified tag with the name provided.

License

Open Source License

Parameter

Parameter Description
node a parameter
name a parameter

Return

The attribute if its defined, or null.

Declaration

public static String getAttribute(Node node, String name, String defVal) 

Method Source Code

//package com.java2s;
/*//from w ww  .j a  va2 s .  co  m
 * Radakan 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.
 *
 * Radakan 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 Radakan.  If not, see <http://www.gnu.org/licenses/>.
 */

import org.w3c.dom.Node;

public class Main {
    /**
     * Returns an attribute of the specified tag with the name provided.
     * 
     * @param node
     * @param name
     * @return The attribute if its defined, or null.
     */
    public static String getAttribute(Node node, String name, String defVal) {
        Node att = node.getAttributes().getNamedItem(name);
        return att == null ? defVal : att.getNodeValue();
    }

    public static String getAttribute(Node node, String name) {
        return getAttribute(node, name, null);
    }
}

Related

  1. getAttribute(Node node, String name)
  2. getAttribute(Node node, String name)
  3. getAttribute(Node node, String name)
  4. getAttribute(Node node, String name)
  5. getAttribute(Node node, String name, String defVal)
  6. getAttribute(Node pNode, String attrName)
  7. getAttribute(Node pNode, String pName)
  8. getAttribute(Node targetElem, String keyName, String defaultValue)
  9. getAttribute(String aAttrName, Node aNode)