Java XML Element Get by Attribute findElementByAttribute(final NodeList list, final String name, final String value)

Here you can find the source of findElementByAttribute(final NodeList list, final String name, final String value)

Description

find Element By Attribute

License

Open Source License

Declaration

public static Element findElementByAttribute(final NodeList list, final String name, final String value) 

Method Source Code


//package com.java2s;
//License from project: GNU General Public License 

import org.w3c.dom.*;

public class Main {
    public static Element findElementByAttribute(final NodeList list, final String name, final String value) {
        for (int i = 0; i < list.getLength(); ++i) {
            if (list.item(i).getNodeType() == Node.ELEMENT_NODE) {
                final Element e = (Element) list.item(i);
                if (e.hasAttribute(name) && e.getAttribute(name).equals(value)) {
                    return e;
                }/*w  w w .  j  a  va2  s.  c  om*/
            }
        }
        return null;
    }
}

Related

  1. findAllElementsByAttribute(Node node, String tagName, String attrName, String attrValue)
  2. findAllElementsByAttributes(Element node, String tagName, String attrName, List attrValues)
  3. findComponent(Element element, String attributeValue)
  4. findElement(Element element, String elementName, String attributeValue)
  5. findElement(Element parent, String elementNS, String elementName, String attrName, String attrValue)
  6. findElementsByAttribute(Element node, String tagName, String attrName, List attrValues)
  7. findElementWithAttributes(Node node, String tagName, Collection attrs)
  8. findElementWithNameAttribute(Element parent, String name)
  9. findElementWithUniqueAttribute(Element root, String elementName, String attribute, String attributeValue)