Java tutorial
//package com.java2s; /** * The contents of this file are subject to the OpenMRS Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://license.openmrs.org * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations * under the License. * * Copyright (C) OpenMRS, LLC. All Rights Reserved. */ import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /** * Finds the first child of a node with the given name * @param parent the parent node * @param name the name * @return the child node */ public static Node findFirstChild(Node parent, String name) { NodeList children = parent.getChildNodes(); for (int i = 0; i < children.getLength(); ++i) { Node node = children.item(i); if (name.equals(node.getNodeName())) { return node; } } return null; } }