Java XML Attribute Get getAttribute(final Node node, final String attribname, final int def)

Here you can find the source of getAttribute(final Node node, final String attribname, final int def)

Description

get Attribute

License

Apache License

Declaration

public static int getAttribute(final Node node, final String attribname, final int def) 

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 getAttribute(final Node node, final String attribname, final int def) {
        final String attr = getAttributeValue(node, attribname);
        if (attr != null) {
            return Integer.parseInt(attr);
        } else {//from w w  w  .j a v a  2s  .co  m
            return def;
        }
    }

    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. getAttribute(Element parent, String localName, String namespaceURI)
  2. getAttribute(File file, String attr)
  3. getAttribute(final List elements, final int index)
  4. getAttribute(final Node iNode, final String iAttributeName)
  5. getAttribute(final Node n, final String attrName, final String defaultValue)
  6. getAttribute(final Node node, final String attributeName)
  7. getAttribute(final Node node, final String name)
  8. getAttribute(final Node xml, final String namespaceURI, final String localName)
  9. getAttribute(NamedNodeMap map, String name)