Here you can find the source of hasChildElementWithAttribute(Element element, String attributeName, String attributeValue)
Parameter | Description |
---|---|
element | the element to look in |
attributeName | the name of the attribute |
attributeValue | the value of the attribute |
public static boolean hasChildElementWithAttribute(Element element, String attributeName, String attributeValue)
//package com.java2s; //License from project: Apache License import org.w3c.dom.Element; import org.w3c.dom.Node; public class Main { /**// w w w. ja v a 2 s. c o m * Looks for a childelement with an attribute with the given name and value * * @param element the element to look in * @param attributeName the name of the attribute * @param attributeValue the value of the attribute * @return true if the given element has a child element with an attribute * where attrname.equals(attributeName) & * attr.value(attributeValue), else false */ public static boolean hasChildElementWithAttribute(Element element, String attributeName, String attributeValue) { if (element == null) { return false; } for (int i = 0; i < element.getChildNodes().getLength(); i++) { Node child = element.getChildNodes().item(i); if ((child.getAttributes().getNamedItem(attributeName) != null) && child.getAttributes().getNamedItem(attributeName).getNodeValue().equals(attributeValue)) { return true; } } return false; } }