Java tutorial
//package com.java2s; /******************************************************************************* * Copyright (c) 2004-2010 Sunil Kamath (IcemanK). All rights reserved. This * program is made available under the terms of the Common Public License v1.0 * which is available at http://www.eclipse.org/legal/cpl-v10.html * * Contributors: Sunil Kamath (IcemanK) - initial API and implementation *******************************************************************************/ import org.w3c.dom.*; public class Main { public static Node findFirstChild(Node node) { return findFirstChild(node, null); } public static Node findFirstChild(Node node, String name) { NodeList childNodes = node.getChildNodes(); int count = childNodes.getLength(); for (int i = 0; i < count; i++) { Node child = childNodes.item(i); if (child instanceof Element && (name == null || child.getNodeName().equals(name))) { return child; } } return null; } }