Here you can find the source of getFirstNamedChild(Node n, String name)
Parameter | Description |
---|---|
n | The parent node |
namespace | The namespace name |
name | The node name |
public static Node getFirstNamedChild(Node n, String name)
//package com.java2s; /*/*from www . ja va 2 s. c om*/ This file is part of p300. p300 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. p300 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 p300. If not, see <http://www.gnu.org/licenses/>. */ import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /** * Check if the given node has a child with the specified name * Return the child of the specified name, or null if not found * @param n The parent node * @param namespace The namespace name * @param name The node name * @return */ public static Node getFirstNamedChild(Node n, String name) { NodeList children = n.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node currentChild = children.item(i); String localName = currentChild.getNodeName(); if (localName != null && localName.equalsIgnoreCase(name)) { return currentChild; } } return null; } }