Java XML Attribute Get getAttribute(Element parent, String localName)

Here you can find the source of getAttribute(Element parent, String localName)

Description

get Attribute

License

Apache License

Declaration

public static String getAttribute(Element parent, String localName) 

Method Source Code


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

import org.w3c.dom.*;

import javax.xml.namespace.QName;

public class Main {
    public static String getAttribute(Element parent, QName name) {
        if (parent == null) {
            return null;
        }/*  ww w  . j  a  v  a2  s. c om*/
        Attr attribute;
        if (name.getNamespaceURI() == null) {
            attribute = parent.getAttributeNode(name.getLocalPart());
        } else {
            attribute = parent.getAttributeNodeNS(name.getNamespaceURI(), name.getLocalPart());
        }
        if (attribute != null) {
            return attribute.getValue();
        } else {
            return null;
        }
    }

    public static String getAttribute(Element parent, String localName) {
        if (parent == null) {
            return null;
        }
        Attr attribute = parent.getAttributeNode(localName);

        if (attribute != null) {
            return attribute.getValue();
        } else {
            return null;
        }
    }
}

Related

  1. getAttribute(Element element, String name)
  2. getAttribute(Element element, String name, String defaultVal)
  3. getAttribute(Element element, String namespace, String name)
  4. getAttribute(Element element, String nodeName)
  5. getAttribute(Element ownerElem, String attrName)
  6. getAttribute(Element parent, String localName, String namespaceURI)
  7. getAttribute(File file, String attr)
  8. getAttribute(final List elements, final int index)
  9. getAttribute(final Node iNode, final String iAttributeName)