Android XML Node Attribute Get getAttribute(Node node, String name)

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

Description

Extracts from node the attribute with the specified name.

License

LGPL

Parameter

Parameter Description
node the node whose attribute we'd like to extract.
name the name of the attribute to extract.

Return

a String containing the trimmed value of the attribute or null if no such attribute exists

Declaration

public static String getAttribute(Node node, String name) 

Method Source Code

//package com.java2s;
/*/* w w  w  .j  a  v a 2s  .com*/
 * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

import org.w3c.dom.*;

public class Main {
    /**
     * Extracts from node the attribute with the specified name.
     * @param node the node whose attribute we'd like to extract.
     * @param name the name of the attribute to extract.
     * @return a String containing the trimmed value of the attribute or null
     * if no such attribute exists
     */
    public static String getAttribute(Node node, String name) {
        if (node == null)
            return null;

        Node attribute = node.getAttributes().getNamedItem(name);
        return (attribute == null) ? null : attribute.getNodeValue().trim();
    }
}

Related

  1. getAttrOfName(Node node, String string)
  2. getAttributeValue(Node node, String attributeName)
  3. getAttributeValue(Node node, String attributeName)
  4. getAttributeValueAsInt(Node node, String attributeName)
  5. getElementAttr(Node element, String attrName)