Java XML Attribute from Node GetNodeAttribute(Node node, String attributeName)

Here you can find the source of GetNodeAttribute(Node node, String attributeName)

Description

Returns the content of the specified attribute in the specified node.

License

LGPL

Parameter

Parameter Description
node The node containing the desired attribute.
attributeName The name of the desired attribute.

Return

The text of the specified attribute. If the attribute doesn't exist in the specified node, the method returns an empty string.

Declaration

public static String GetNodeAttribute(Node node, String attributeName) 

Method Source Code

//package com.java2s;
/*/*from   ww w.j  a  v a 2 s .c o  m*/
 * JLib - Publicitas Java library.
 *
 * Copyright (c) 2005, 2006, 2007, 2008 Publicitas SA.
 * Licensed under LGPL (LGPL-LICENSE.txt) license.
 */

import org.w3c.dom.Element;

import org.w3c.dom.Node;

public class Main {
    /**
     * Returns the content of the specified attribute in the specified node.
     * @param node The node containing the desired attribute.
     * @param attributeName The name of the desired attribute.
     * @return The text of the specified attribute. If the attribute doesn't exist
     * in the specified node, the method returns an empty string.
     */
    public static String GetNodeAttribute(Node node, String attributeName) {
        Element x = (Element) node;
        return x.getAttribute(attributeName);
    }
}

Related

  1. getNodeAttr(String attrName, Node node)
  2. getNodeAttr(String tagName, String attrName, NodeList nodes)
  3. getNodeAttribute(Node n, String as)
  4. getNodeAttribute(Node n, String attrName)
  5. getNodeAttribute(Node n, String name)
  6. getNodeAttribute(Node node, String attributeName)
  7. getNodeAttribute(Node node, String attributeName, String defaultValue)
  8. getNodeAttribute(Node node, String name)
  9. getNodeAttribute(Node node, String name)