Java XML Attribute Get getAttribute(Element element, String attr)

Here you can find the source of getAttribute(Element element, String attr)

Description

Return the named attribute of the argument element, or null if it does not exist.

License

LGPL

Parameter

Parameter Description
element The element to search for a named attribute
attr The attribute name

Return

The attribute String, or null if it does not exist.

Declaration

public static String getAttribute(Element element, String attr) 

Method Source Code

//package com.java2s;
/*****************************************************************************
 *                        Web3d Consortium Copyright (c) 2007 - 2008
 *                               Java Source
 *
 * This source is licensed under the GNU LGPL v2.1
 * Please read http://www.gnu.org/copyleft/lgpl.html for more information
 *
 * This software comes with the standard NO WARRANTY disclaimer for any
 * purpose. Use it at your own risk. If there's a problem you get to fix it.
 *
 *****************************************************************************/

import org.w3c.dom.Element;

public class Main {
    /**//w ww .j  ava2s .c  o  m
     * Return the named attribute of the argument element, or
     * null if it does not exist.
     *
     * @param element The element to search for a named attribute
     * @param attr The attribute name
     * @return The attribute String, or null if it does not exist.
     */
    public static String getAttribute(Element element, String attr) {
        String value = element.getAttribute(attr);
        if (value.equals("")) {
            value = null;
        }
        return (value);
    }
}

Related

  1. getAttribute(Element el, String attrName)
  2. getAttribute(Element el, String attrName)
  3. getAttribute(Element elem, String attName, boolean mandatory)
  4. getAttribute(Element elem, String attName, boolean mandatory)
  5. getAttribute(Element elem, String name, String def)
  6. getAttribute(Element element, String attribute)
  7. getAttribute(Element element, String attribute, String defaultValue)
  8. getAttribute(Element element, String attributeName)
  9. getAttribute(Element element, String attributeName)