Here you can find the source of getChildNode(Node root, String childName)
Parameter | Description |
---|---|
root | a parameter |
string | a parameter |
public static Node getChildNode(Node root, String childName)
//package com.java2s; /*/*www. j a v a 2 s. c om*/ * This file is part of smarthomatic, http://www.smarthomatic.org. * Copyright (c) 2013 Uwe Freese * * smarthomatic is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your * option) any later version. * * smarthomatic is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * Public License for more details. * * You should have received a copy of the GNU General Public License along * with smarthomatic. If not, see <http://www.gnu.org/licenses/>. */ import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /** * Instead of using XPathAPI.selectSingleNode(root, "name")); * use getChildNode(root, "name"); This is much quicker! * @param root * @param string */ public static Node getChildNode(Node root, String childName) { NodeList nl = root.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { if (nl.item(i).getNodeName().equals(childName)) { return nl.item(i); } } System.err.println("Childnode " + childName + " not found!"); return null; } }