Java Utililty Methods XML Attribute Get

List of utility methods to do XML Attribute Get

Description

The list of methods to do XML Attribute Get are organized into topic(s).

Method

booleangetAttributeBoolean(Element el, String label)
get Attribute Boolean
String s = el.getAttribute(label);
return Boolean.valueOf(s).booleanValue();
booleangetAttributeBoolean(final Element element, final String name)
Locate attribute tagged 'name', return its boolean value.
String s = element.getAttribute(name);
return s.equalsIgnoreCase("true");
BooleangetAttributeBoolean(final Node node, final String name, final Boolean defaultValue)
get Attribute Boolean
String value = getAttributeText(node, name);
if (value == null)
    return defaultValue;
if ("yes".equalsIgnoreCase(value))
    return true;
if ("no".equalsIgnoreCase(value))
    return false;
return Boolean.parseBoolean(value);
...
BooleangetAttributeBoolean(Node node, String attributeName)
get Attribute Boolean
String value = getAttribute(node, attributeName, null);
return (value == null ? null : Boolean.valueOf(value));
booleangetAttributeBoolean(Node node, String name)
Gets the boolean value of a named attribute of a node.
String s = getAttributeString(node, name);
if (s != null && s.length() > 0) {
    return (s.compareToIgnoreCase("1") == 0);
} else
    return false;
booleangetAttributeBooleanByName(NamedNodeMap nnm, String name)
Searches throgh the passed NamedNodeMap for an attribute.
for (int i = 0; i < nnm.getLength(); i++) {
    Attr attr = (Attr) nnm.item(i);
    if (attr.getName().equalsIgnoreCase(name)) {
        String tmp = attr.getValue().toLowerCase();
        if (tmp.equalsIgnoreCase("true"))
            return true;
        if (tmp.equalsIgnoreCase("false"))
            return false;
...
booleangetAttributeBooleanByName(NamedNodeMap nnm, String name)
Searches throgh the passed NamedNodeMap for an attribute.
for (int i = 0; i < nnm.getLength(); i++) {
    Attr attr = (Attr) nnm.item(i);
    if (attr.getName().equalsIgnoreCase(name)) {
        String tmp = attr.getValue().toLowerCase();
        if (tmp.equalsIgnoreCase("true"))
            return true;
        if (tmp.equalsIgnoreCase("false"))
            return false;
...
StringgetAttributeByIndex(final Element element, final int index)
get Attribute By Index
return getAttribute(getElementsFromNodeList(element.getChildNodes()), index);
StringgetAttributeByLocalName(XMLStreamReader reader, String localName)
get Attribute By Local Name
String result = "";
for (int i = 0; i < reader.getAttributeCount(); i++) {
    QName attribute = reader.getAttributeName(i);
    if (attribute != null && attribute.getLocalPart().equals(localName)) {
        result = reader.getAttributeValue(i);
return result;
...
StringgetAttributeByName(final List elements, final String attributeName)
get Attribute By Name
for (final Element element : elements) {
    final String value = getAttributeFromElement(element, attributeName);
    if (value != null) {
        return value;
return null;