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

booleangetAttributeAsBoolean(Element element, String attrName, boolean defValue)
get Attribute As Boolean
String value = element.getAttribute(attrName);
try {
    if ((value != null) && (value.length() > 0)) {
        return Boolean.valueOf(value).booleanValue();
} catch (Exception ex) {
return defValue;
...
booleangetAttributeAsBoolean(Element element, String attrName, boolean defValue)
Get the value of the given attribute of this Element as a boolean value.
String value = element.getAttribute(attrName);
try {
    if ((value != null) && (value.length() > 0)) {
        return Boolean.valueOf(value).booleanValue();
} catch (Exception ex) {
return defValue;
...
booleangetAttributeAsBoolean(Element element, String name)
get Attribute As Boolean
String value = element.getAttribute(name);
if (value == null) {
    return false;
return Boolean.parseBoolean(value);
booleangetAttributeAsBoolean(NamedNodeMap map, String name)
Get a named value from the NamedNodeMap as a boolean.
boolean value = false;
try {
    value = (getAttribute(map, name)).equals("1");
} catch (Exception e) {
return value;
IntegergetAttributeAsInteger(Element element, String attrName, Integer defValue)
get Attribute As Integer
try {
    return Integer.valueOf(element.getAttribute(attrName));
} catch (Exception ex) {
return defValue;
LonggetAttributeAsLong(Element element, String attrName, Long defValue)
Get the value of the given attribute of this Element as a java.lang.Long value.
try {
    return Long.valueOf(element.getAttribute(attrName));
} catch (Exception ex) {
return defValue;
StringgetAttributeAsString(NamedNodeMap attributes, String name)
Get an attribute's value and return an empty string, of the attribute is not specified
Attr attribute;
String value = ""; 
attribute = (Attr) attributes.getNamedItem(name);
if (attribute != null) {
    value = attribute.getValue();
return value;
StringgetAttributeAsString(XMLStreamReader reader, String name)
Returns the string value of an attribute.
return reader.getAttributeValue(null, name);
StringgetAttributeAsURIString(XMLStreamReader reader, String name)
TUSCANY-242 Returns the URI value of an attribute as a string and first applies the URI whitespace processing as defined in section 4.3.6 of XML Schema Part2: Datatypes [http://www.w3.org/TR/xmlschema-2/#rf-facets].
String uri = reader.getAttributeValue(null, name);
if (uri != null) {
    uri = uri.replace('\t', ' ');
    uri = uri.replace('\n', ' ');
    uri = uri.replace('\r', ' ');
    uri = uri.trim();
    StringBuilder sb = new StringBuilder(uri.length());
    boolean spaceFound = false;
...
booleangetAttributeBoolean(Element aElement, String aAttributeName)
Returns the boolean value of the specified attribute from the given Element.
return "true".equals(getAttribute(aElement, aAttributeName));