Java Utililty Methods XML Attribute from Element

List of utility methods to do XML Attribute from Element

Description

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

Method

floatgetFloatAttribute(Element element, String name)
get Float Attribute
String s = getTrimmedAttribute(element, name);
return s.isEmpty() ? 0f : Float.parseFloat(s);
FloatgetFloatAttribute(String name, Element el)
Gets the value of the DOM element's attribute with the given name as a Float, or null if the value is not a float.
return stringToFloat(getAttribute(name, el));
StringgetHeadAttr(Element annotU, String attrName)
get Head Attr
NodeList nl = annotU.getElementsByTagName("head");
if (nl == null)
    return "";
Element head = (Element) nl.item(0);
if (head == null)
    return "";
NodeList notes = head.getElementsByTagName("note");
for (int i = 0; i < notes.getLength(); i++) {
...
AttrgetIdAttribute(Element domElement)
Gets the ID attribute of a DOM element.
if (!domElement.hasAttributes()) {
    return null;
NamedNodeMap attributes = domElement.getAttributes();
Attr attribute;
for (int i = 0; i < attributes.getLength(); i++) {
    attribute = (Attr) attributes.item(i);
    if (attribute.isId()) {
...
StringgetIdAttributeValue(Element elem, String name)
Returns the attribute value for the attribute with the specified name.
Attr attr = elem.getAttributeNodeNS(null, name);
if (attr != null && !attr.isId()) {
    elem.setIdAttributeNode(attr, true);
return (attr == null) ? null : attr.getValue();
intgetIntAttr(Element elem, String attName)
Return the value of an integer attribute or zero
return getIntAttr(elem, attName, 0);
intgetIntAttribute(Element el, String name)
get Int Attribute
String s = el.getAttribute(name);
if (s != null && s.length() > 0) {
    return Integer.parseInt(s);
return 0;
intgetIntAttribute(Element elem, String attName, boolean mandatory, int defaultValue)
getIntAttribute purpose.
String attValue = getAttribute(elem, attName, mandatory);
if (!mandatory && (attValue == null)) {
    return defaultValue;
try {
    return Integer.parseInt(attValue);
} catch (Exception ex) {
    if (mandatory) {
...
intgetIntAttribute(Element elem, String attName, boolean mandatory, int defaultValue)
getIntAttribute purpose.
String attValue = getAttribute(elem, attName, mandatory);
if (!mandatory && (attValue == null)) {
    return defaultValue;
try {
    return Integer.parseInt(attValue);
} catch (Exception ex) {
    if (mandatory) {
...
intgetIntAttribute(Element element, String attribute)
get Int Attribute
String value = element.getAttribute(attribute);
int result = 1;
if (value != null && value.length() != 0) {
    result = Integer.parseInt(value);
return result;