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

StringgetAttributeNSOrNull(Element e, String name, String nsURI)
get Attribute NS Or Null
Attr a = e.getAttributeNodeNS(nsURI, name);
if (a == null)
    return null;
return a.getValue();
NodegetAttributeOrNull(String attribute, Element element)
get Attribute Or Null
if (!element.hasAttributes()) {
    return null;
NamedNodeMap attributes = element.getAttributes();
return attributes.getNamedItem(attribute);
StringgetAttributePropertyFromElement(final Element element, final String attribute)
get Attribute Property From Element
return element.getAttribute(attribute);
MapgetAttributes(Element el)
get attribute map from the element
Map<String, String> list = new LinkedHashMap<String, String>();
NamedNodeMap map = el.getAttributes();
for (int i = 0; i < map.getLength(); i++) {
    list.put(map.item(i).getNodeName(), map.item(i).getNodeValue());
return list;
ListgetAttributes(Element el)
Returns a list of attributes of an element.
String nodename, prefix = null;
List attrs = new Vector();
NamedNodeMap attrMap = el.getAttributes();
for (int i = 0; i < attrMap.getLength(); i++) {
    nodename = attrMap.item(i).getNodeName();
    prefix = attrMap.item(i).getPrefix();
    if (ATTR_XMLNS.equals(nodename) || ATTR_XMLNS.equals(prefix)) {
        continue;
...
MapgetAttributes(Element el)
get Attributes
Map<String, String> retval = new HashMap<String, String>();
NamedNodeMap list = el.getAttributes();
for (int i = 0; i < list.getLength(); i++) {
    Node node = list.item(i);
    if (node instanceof Attr) {
        Attr a = (Attr) node;
        retval.put(a.getName(), a.getValue());
return retval;
MapgetAttributes(Element element)
get Attributes
NamedNodeMap attributes = element.getAttributes();
Map<String, String> result = new HashMap<String, String>();
int n = attributes.getLength();
for (int i = 0; i < n; i++) {
    Attr attribute = (Attr) attributes.item(i);
    result.put(attribute.getName(), attribute.getValue());
return result;
...
MapgetAttributes(Element element)
Get attributes without namespace declarations of specified element.
Map<String, String> ret = new HashMap<String, String>();
NamedNodeMap attrs = element.getAttributes();
for (int i = 0; i < attrs.getLength(); i++) {
    Attr attr = (Attr) attrs.item(i);
    String attrName = attr.getName();
    if (!attrName.startsWith(XMLNS_PREFIX_COLON) && !attrName.equals(XMLNS_PREFIX)) {
        ret.put(attrName, attr.getValue());
return ret;
String[][]getAttributes(Element root, String elementName, String[] wantedAttributes)
get Attributes
NodeList list = root.getElementsByTagName(elementName);
String[][] ret = new String[list.getLength()][wantedAttributes.length];
for (int i = 0; i < list.getLength(); i++) {
    Element elem = (Element) list.item(i);
    for (int j = 0; j < wantedAttributes.length; j++) {
        ret[i][j] = elem.getAttribute(wantedAttributes[j]);
return ret;
MapgetAttributes(final Element el)
get Attributes
final Map<QName, String> attmap = new HashMap<QName, String>();
final NamedNodeMap attribs = el.getAttributes();
for (int i = 0; i < attribs.getLength(); i++) {
    final Attr attr = (Attr) attribs.item(i);
    final String name = attr.getName();
    final QName qname = resolveQName(el, name);
    final String value = attr.getNodeValue();
    attmap.put(qname, value);
...