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

StringgetAttr(Node node, String name, String defaultValue)
get Attr
String result = defaultValue;
if (node != null && node.getAttributes() != null && node.getAttributes().getNamedItem(name) != null)
    result = node.getAttributes().getNamedItem(name).getNodeValue();
return result;
booleangetAttrBool(Node n, String name)
get Attr Bool
if (n == null)
    return false; 
Node nn = n.getAttributes().getNamedItem(name);
if (nn == null)
    return false; 
String value = nn.getNodeValue();
if (value == null)
    return false; 
...
DategetAttrDate(Element elem, String localName)
Returns the Date value of the unqualified attribute with the given local name belonging to the given element, or null if the attribute is not present.
String str = getAttrString(elem, localName);
if (str != null) {
    try {
        return dateFormat.parse(str);
    } catch (ParseException ignored) {
return null;
...
StringgetAttrib(NamedNodeMap attribs, String name)
get Attrib
return attribs.getNamedItem(name).getNodeValue();
BooleangetAttribAsBoolean(Element e, String name, Boolean dft)
get Attrib As Boolean
if (getAttribute(e, name) == null)
    return dft;
else
    return Boolean.parseBoolean(getAttribute(e, name));
FloatgetAttribAsFloat(Element e, String name, Float dft)
get Attrib As Float
String num = getAttribute(e, name);
return num.equals("") ? dft : Float.parseFloat(num);
booleangetAttribBoolean(Element ele, String name)
Parses the given attribute of this tag and returns it as a boolean.
String sval = ele.getAttribute(name);
return sval.toLowerCase().equals("true");
StringgetAttribByName(Element node, String name)
get Attrib By Name
return node.getAttribute(name);
floatgetAttribFloat(Element ele, String name)
Parses the given attribute of this tag and returns it as a float
String sval = ele.getAttribute(name);
float val = 0.0f;
try {
    val = Float.parseFloat(sval);
} catch (Exception e) {
return val;
intgetAttribIntHex(Element ele, String name)
Parses the given attribute of this tag as a hexadecimal encoded string and returns it as an int
String sval = ele.getAttribute(name);
int val = 0;
try {
    val = Integer.parseInt(sval, 16);
} catch (Exception e) {
return val;