Java XML Attribute Get getAttribute(Element aElement, String aAttr, String aDefault)

Here you can find the source of getAttribute(Element aElement, String aAttr, String aDefault)

Description

Retrieves the given attribute from the given Element.

License

Open Source License

Parameter

Parameter Description
aElement The owning <code>Element</code>.
aAttr The name of the attribute.
aDefault The default value if the attribute value is empty.

Declaration

public static String getAttribute(Element aElement, String aAttr,
        String aDefault) 

Method Source Code

//package com.java2s;

import org.w3c.dom.Element;

public class Main {
    /**/* w ww.  j a  va  2  s . c om*/
     * Returns the value of the specified attribute from the given Element.
     *
     * @param aElement The owning <code>Element</code>.
     * @param aAttributeName The name of the attribute.
     * @return String
     */
    public static String getAttribute(Element aElement,
            String aAttributeName) {
        return aElement.getAttribute(aAttributeName);
    }

    /**
     * Retrieves the given attribute from the given Element.  If the attribute had an empty String
     * value then the default argument is returned.
     *
     * @param aElement The owning <code>Element</code>.
     * @param aAttr The name of the attribute.
     * @param aDefault The default value if the attribute value is empty.
     */
    public static String getAttribute(Element aElement, String aAttr,
            String aDefault) {
        String str = getAttribute(aElement, aAttr);
        return str.equals("") ? aDefault : str; //$NON-NLS-1$
    }
}

Related

  1. getAttribByName(Element node, String name)
  2. getAttribFloat(Element ele, String name)
  3. getAttribIntHex(Element ele, String name)
  4. getAttribString(Element ele, String name)
  5. getAttribURL(Element ele, String name, URL docRoot)
  6. getAttribute(Element e, String attName)
  7. getAttribute(Element e, String attribute)
  8. getAttribute(Element e, String attrName, String def)
  9. getAttribute(Element e, String name)