Java tutorial
//package com.java2s; /******************************************************************************* * Copyright (c) 2015 CA. All rights reserved. * * This source file is licensed under the terms of the Eclipse Public License 1.0 * For the full text of the EPL please see https://www.eclipse.org/legal/epl-v10.html *******************************************************************************/ import org.w3c.dom.Document; import org.w3c.dom.NodeList; import org.w3c.dom.Node; public class Main { /** * Search a first node by name in the document * * @param doc source document * @param nodeName the node name for searching * @return Node with the specified name * @see Node * @throws Exception */ public static Node findChildNodesByName(Document doc, String nodeName) throws Exception { Node node = null; NodeList nl = doc.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { node = nl.item(i); if (node.getNodeName().equals(nodeName)) { break; } } return node; } }