Here you can find the source of getElementWithAttributeNS(Element element, String namespaceURI, String attribute, String value)
Parameter | Description |
---|---|
element | Element whose children we want to search |
namespaceURI | Attribute namespace URI |
attribute | Attribute name |
value | Attribute value |
public static Element getElementWithAttributeNS(Element element, String namespaceURI, String attribute, String value)
//package com.java2s; //License from project: Apache License import org.w3c.dom.NodeList; import org.w3c.dom.Element; import org.w3c.dom.Node; public class Main { /** Get the first element descendant having the specified attribute name and value.//from w ww.ja va2s. c o m @param element Element whose children we want to search @param namespaceURI Attribute namespace URI @param attribute Attribute name @param value Attribute value @return The first element having this attribute value */ public static Element getElementWithAttributeNS(Element element, String namespaceURI, String attribute, String value) { String attr = element.getAttributeNS(namespaceURI, attribute); if (attr != null && attr.equals(value)) { return element; } NodeList childs = element.getChildNodes(); for (int i = 0; i < childs.getLength(); i++) { Node node = childs.item(i); if (Node.ELEMENT_NODE == node.getNodeType()) { Element e = getElementWithAttributeNS((Element) node, namespaceURI, attribute, value); if (e != null) return e; } } return null; } }