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

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

Description

get Tag Attribute

License

Open Source License

Declaration

public static String getTagAttribute(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 {
    public static String getTagAttribute(String sTag, String sAtt, Element eElement) {
        Node node;//from w  w w .  ja va 2 s . c  o  m
        String name;

        NodeList nList = eElement.getChildNodes();

        for (int i = 0; i < nList.getLength(); i++) {
            node = nList.item(i);
            name = node.getNodeName();

            if (name.equals(sTag)) {
                node = node.getAttributes().getNamedItem(sAtt);

                if (node != null)
                    return node.getNodeValue().toString();
                else
                    return null;
            }
        }

        return null;
    }
}

Related

  1. getStringAttribute(Element e, String name, String def)
  2. getStringAttribute(Element el, String attribute)
  3. getStringAttributeValue(Element element, String attribute)
  4. getStringAttributeValue(final Element element, final String attributeName)
  5. getStringAttributeValue(final Element element, final String attributeName)
  6. getTagAttribute(XMLStreamReader xmler, String attribute, String defaultValue)
  7. getTagAttributeRecursive(String sTag, String sAtt, Element eElement)
  8. getTagAttributes(Element element)
  9. getThisClassTypeAttr(Element methodNode)