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

StringgetStringAttributeValue(Element element, String attribute)
get String Attribute Value
Attr a = element.getAttributeNode(attribute);
return a != null ? a.getValue() : null;
StringgetStringAttributeValue(final Element element, final String attributeName)
get String Attribute Value
if (null == element) {
    return null;
final String str = element.getAttribute(attributeName);
return str;
StringgetStringAttributeValue(final Element element, final String attributeName)
get String Attribute Value
if (null == element) {
    return null;
final String str = element.getAttribute(attributeName);
return str;
StringgetTagAttribute(String sTag, String sAtt, Element eElement)
get Tag Attribute
Node node;
String name;
NodeList nList = eElement.getChildNodes();
for (int i = 0; i < nList.getLength(); i++) {
    node = nList.item(i);
    name = node.getNodeName();
    if (name.equals(sTag)) {
        node = node.getAttributes().getNamedItem(sAtt);
...
StringgetTagAttribute(XMLStreamReader xmler, String attribute, String defaultValue)
get Tag Attribute
if (attribute != null) {
    String val = xmler.getAttributeValue(null, attribute);
    if (val != null) {
        return val;
return defaultValue;
StringgetTagAttributeRecursive(String sTag, String sAtt, Element eElement)
XML helper to retrieve an attribute of a node
NodeList nList = eElement.getElementsByTagName(sTag);
if (nList == null)
    return null;
Node node = nList.item(0);
if (node == null)
    return null;
Node attNode = node.getAttributes().getNamedItem(sAtt);
if (attNode == null)
...
MapgetTagAttributes(Element element)
get Tag Attributes
Map<String, String> attributes = new LinkedHashMap<String, String>();
NamedNodeMap sourceAttributes = element.getAttributes();
for (int i = 0; i < sourceAttributes.getLength(); ++i) {
    Attr attribute = (Attr) sourceAttributes.item(i);
    attributes.put(attribute.getName(), attribute.getValue());
return attributes;
AttrgetThisClassTypeAttr(Element methodNode)
get This Class Type Attr
return methodNode.getAttributeNode("thisClass");
StringgetTrimedAttribute(Element elem, String attr_name)
get Trimed Attribute
return trimOuterWhitespace(elem.getAttribute(attr_name));
StringgetValue(final Element elem, final String attrName)
Get attribute value.
final Attr attr = elem.getAttributeNode(attrName);
if (attr != null && !attr.getValue().isEmpty()) {
    return attr.getValue();
return null;