Java Utililty Methods XML Attribute from Node

List of utility methods to do XML Attribute from Node

Description

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

Method

voidgenerateIds(Node root, String attrName)
adds an attribute with random value to all elements, that do not have an attribute with the specified name.
if (root.getNodeType() == Node.ELEMENT_NODE) {
    Element e = (Element) root;
    String id = e.getAttribute(attrName);
    if (id == null || id.length() == 0)
        e.setAttribute(attrName, randomId());
NodeList list = root.getChildNodes();
int N = list.getLength();
...
VectorgetALLAttribute(final Node iNode)
get ALL Attribute
Vector<Attr> result = new Vector<Attr>();
if (iNode != null) {
    NamedNodeMap attrList = iNode.getAttributes();
    int numAttr = attrList.getLength();
    Attr currentAttrNode = null;
    for (int k = 0; k < numAttr; k++) {
        currentAttrNode = (Attr) attrList.item(k);
        result.add(currentAttrNode);
...
floatgetFloatAttribute(Node node, String name, float defVal)
get Float Attribute
String att = getAttribute(node, name);
if (att == null)
    return defVal;
return Float.parseFloat(att);
floatgetFloatAttribute(Node node, String name, float defVal)
get Float Attribute
String att = getAttribute(node, name);
if (att == null)
    return defVal;
return Float.parseFloat(att);
intgetIntAttr(Node node, String attrName)
get Int Attr
String sValue = getAttr(node, attrName);
if (sValue == null) {
    return Integer.MIN_VALUE;
return Integer.parseInt(sValue);
intgetIntAttribute(Node n, String s)
get Int Attribute
return Integer.parseInt(getAttribute(n, s));
intgetIntAttribute(Node node, String attr)
get Int Attribute
return getIntAttribute(node, attr, 0);
intgetIntAttribute(Node node, String attributeName, int defaultValue)
get Int Attribute
String value = getAttribute(node, attributeName);
if (value == null) {
    return defaultValue;
return Integer.parseInt(value);
intgetIntAttribute(Node node, String name, int defVal)
get Int Attribute
String att = getAttribute(node, name);
if (att == null)
    return defVal;
return Integer.parseInt(att);
intgetIntAttributeRequired(Node node, String attributeName)
get Int Attribute Required
String string = getStringAttributeRequired(node, attributeName);
try {
    return Integer.parseInt(string);
} catch (Exception e) {
    throw new Exception("Could not read integer from value '" + string + "' in attribute '" + attributeName
            + "' in node '" + node.getLocalName() + "'");