Java XML Attribute from Element getTagAttributeRecursive(String sTag, String sAtt, Element eElement)

Here you can find the source of getTagAttributeRecursive(String sTag, String sAtt, Element eElement)

Description

XML helper to retrieve an attribute of a node

License

Open Source License

Parameter

Parameter Description
sTag Tag name
sAtt Attribute name
eElement The XML node

Return

Attribute value

Declaration

public static String getTagAttributeRecursive(String sTag, String sAtt, Element eElement) 

Method Source Code

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

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    /**//from www.ja va2  s.c  o m
     * XML helper to retrieve an attribute of a node 
     * @param sTag Tag name
     * @param sAtt Attribute name
     * @param eElement The XML node
     * @return Attribute value
     */
    public static String getTagAttributeRecursive(String sTag, String sAtt, Element eElement) {
        NodeList nList = eElement.getElementsByTagName(sTag);

        if (nList == null)
            return null;

        Node node = nList.item(0);

        if (node == null)
            return null;

        Node attNode = node.getAttributes().getNamedItem(sAtt);

        if (attNode == null)
            return null;

        return attNode.getNodeValue().toString();
    }
}

Related

  1. getStringAttributeValue(Element element, String attribute)
  2. getStringAttributeValue(final Element element, final String attributeName)
  3. getStringAttributeValue(final Element element, final String attributeName)
  4. getTagAttribute(String sTag, String sAtt, Element eElement)
  5. getTagAttribute(XMLStreamReader xmler, String attribute, String defaultValue)
  6. getTagAttributes(Element element)
  7. getThisClassTypeAttr(Element methodNode)
  8. getTrimedAttribute(Element elem, String attr_name)
  9. getValue(final Element elem, final String attrName)