Java XML Attribute Get getAttributeIntArray(final Node node, final String attribname)

Here you can find the source of getAttributeIntArray(final Node node, final String attribname)

Description

get Attribute Int Array

License

Apache License

Declaration

public static int[] getAttributeIntArray(final Node node, final String attribname) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

public class Main {
    public static int[] getAttributeIntArray(final Node node, final String attribname) {
        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]);
            }/*from  w w  w .  j ava2 s . co m*/
            return result;
        }
        return null;
    }

    public static String getAttributeValue(final Node node, final String attribname) {
        final NamedNodeMap attributes = node.getAttributes();
        String att = null;
        if (attributes != null) {
            final Node attribute = attributes.getNamedItem(attribname);
            if (attribute != null) {
                att = attribute.getNodeValue();
            }
        }
        return att;
    }
}

Related

  1. getAttributeFloatValue(String attribute, NamedNodeMap namedNodeMap)
  2. getAttributeFromClosestAncestorOfAnyKind(Node node, String attributeName)
  3. getAttributeIfExists(Node node, String name)
  4. getAttributeIgnoreCase(Element element, String attributeName)
  5. getAttributeIgnoreCase(Element element, String string)
  6. getAttributeInteger(String filename, Element parent, String name)
  7. getAttributeInteger(String filename, Element parent, String name)
  8. getAttributeIntValue(Node n, String item, int dflt)
  9. getAttributeList(NamedNodeMap attributeMap)