Here you can find the source of getChild(Node node, String name, String attrName, String attrValue)
Parameter | Description |
---|---|
node | Node. |
name | Name. |
attrName | Attribute name. |
attrValue | Attribute value. |
public static Element getChild(Node node, String name, String attrName, String attrValue)
//package com.java2s; /* Please see the license information at the end of this file. */ import org.w3c.dom.*; public class Main { /** Gets a child element of a node by name. *// ww w . j a v a2 s. co m * @param node Node. * * @param name Name. * * @return First child element with given tag name, or * null if none found. */ public static Element getChild(Node node, String name) { NodeList children = node.getChildNodes(); int numChildren = children.getLength(); for (int i = 0; i < numChildren; i++) { Node child = children.item(i); if (child.getNodeType() != Node.ELEMENT_NODE) continue; if (child.getNodeName().equals(name)) return (Element) child; } return null; } /** Gets a child element of a node by name and attribute value. * * @param node Node. * * @param name Name. * * @param attrName Attribute name. * * @param attrValue Attribute value. * * @return First child element with given tag name and * given attribute value, or null if none found. */ public static Element getChild(Node node, String name, String attrName, String attrValue) { NodeList children = node.getChildNodes(); int numChildren = children.getLength(); for (int i = 0; i < numChildren; i++) { Node child = children.item(i); if (child.getNodeType() != Node.ELEMENT_NODE) continue; if (child.getNodeName().equals(name)) { Element el = (Element) child; if (attrValue.equals(el.getAttribute(attrName))) return el; } } return null; } }