Java XML Attribute Get getAttribute(final Node n, final String attrName, final String defaultValue)

Here you can find the source of getAttribute(final Node n, final String attrName, final String defaultValue)

Description

get Attribute

License

Open Source License

Declaration

public static String getAttribute(final Node n, final String attrName, final String defaultValue) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import org.w3c.dom.Attr;
import org.w3c.dom.Node;

public class Main {
    public static String getAttribute(final Node n, final String attrName, final String defaultValue) {
        if (n.getAttributes().getNamedItem(attrName) != null) {
            return ((Attr) n.getAttributes().getNamedItem(attrName)).getValue();
        }/*from   w  w  w  . ja  va2  s . c  o  m*/
        return defaultValue;
    }
}

Related

  1. getAttribute(Element parent, String localName)
  2. getAttribute(Element parent, String localName, String namespaceURI)
  3. getAttribute(File file, String attr)
  4. getAttribute(final List elements, final int index)
  5. getAttribute(final Node iNode, final String iAttributeName)
  6. getAttribute(final Node node, final String attribname, final int def)
  7. getAttribute(final Node node, final String attributeName)
  8. getAttribute(final Node node, final String name)
  9. getAttribute(final Node xml, final String namespaceURI, final String localName)