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

int[]getAttributeIntArray(final Node node, final String attribname)
get Attribute Int Array
final String attr = getAttributeValue(node, attribname);
if (attr != null) {
    String[] splits = attr.split("[,\\s]");
    int[] result = new int[splits.length];
    for (int i = 0; i < splits.length; i++) {
        result[i] = Integer.valueOf(splits[i]);
    return result;
...
IntegergetAttributeInteger(String filename, Element parent, String name)
get Attribute Integer
String attrStr = parent.getAttribute(name);
if (attrStr == null) {
    return null;
return textToInteger(filename, attrStr, name);
IntegergetAttributeInteger(String filename, Element parent, String name)
Gets the attribute integer.
String attrStr = parent.getAttribute(name);
if (attrStr == null) {
    return null;
return textToInteger(filename, attrStr, name);
intgetAttributeIntValue(Node n, String item, int dflt)
Method getAttributeIntValue.
final Node d = n.getAttributes().getNamedItem(item);
if (d == null) {
    return dflt;
final String val = d.getNodeValue();
if (val == null) {
    return dflt;
return Integer.parseInt(val);
StringgetAttributeList(NamedNodeMap attributeMap)
a concatenated list of the node's attributes.
String attribs = "";
if (attributeMap != null) {
    attributeMap.getLength();
    for (int i = 0; i < attributeMap.getLength(); i++) {
        Node n = attributeMap.item(i);
        attribs += n.getNodeName() + "=\"" + n.getNodeValue() + "\"  ";
return attribs;
MapgetAttributeMap(final Node node)
Returns a map of the passed node's attributes
if (node == null)
    throw new IllegalArgumentException("The passed node was null");
final NamedNodeMap nnm = node.getAttributes();
final int size = nnm.getLength();
if (size == 0)
    return Collections.emptyMap();
final Map<String, String> map = new LinkedHashMap<String, String>(size);
for (int i = 0; i < size; i++) {
...
MapgetAttributeMap(NamedNodeMap nodeMap)
Change NamedNodeMap type to Map type
if (nodeMap != null) {
    int len = nodeMap.getLength();
    HashMap map = new HashMap();
    for (int i = 0; i < len; i++) {
        Node node = nodeMap.item(i);
        String name = node.getNodeName();
        String value = node.getNodeValue();
        if (name != null && !name.trim().equalsIgnoreCase("") && value != null) 
...
MapgetAttributeMap(XMLEvent evt)
get Attribute Map
Map<String, String> ret = new HashMap<String, String>();
if (evt.isStartElement()) {
    StartElement start = evt.asStartElement();
    Iterator<Attribute> iterator = start.getAttributes();
    while (iterator.hasNext()) {
        Attribute a = iterator.next();
        ret.put(a.getName().getLocalPart(), a.getValue());
return ret;
HashMapgetAttributeMap(XMLStreamReader xmlStreamReader)
get Attribute Map
HashMap<String, String> attributeMap = new HashMap<String, String>();
int attributeCount = xmlStreamReader.getAttributeCount();
for (int i = 0; i < attributeCount; i++) {
    String attributeName = xmlStreamReader.getAttributeName(i).getLocalPart();
    String attributeValue = xmlStreamReader.getAttributeValue(i);
    attributeMap.put(attributeName, attributeValue);
return attributeMap;
...
StringgetAttributeName(Field field)
get Attribute Name
XmlAttribute attribute = (XmlAttribute) field.getAnnotation(XmlAttribute.class);
return !DEFAULT_NAME.equals(attribute.name()) ? attribute.name() : field.getName();