Here you can find the source of getChildNode(Node parent, String tagName)
Parameter | Description |
---|---|
parent | a parameter |
tagName | a parameter |
Parameter | Description |
---|---|
Exception | if no child with the given tag name is found |
public static Node getChildNode(Node parent, String tagName) throws Exception
//package com.java2s; //License from project: Open Source License import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /**/*w w w .ja v a 2 s . co m*/ * Get the first child with a certain tag name * * @param parent * @param tagName * @return child Node with the given tag name * @throws Exception if no child with the given tag name is found */ public static Node getChildNode(Node parent, String tagName) throws Exception { NodeList children = parent.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node currentNode = children.item(i); if (currentNode.getLocalName().equalsIgnoreCase(tagName)) { return currentNode; } } throw new Exception("Child Node ['" + tagName + "'] not found."); } }