Here you can find the source of getNode(final Node iNode, final String iNodeName)
Parameter | Description |
---|---|
iNode | The provided node structure to be traversed. |
iNodeName | The name of the node being searched for. |
public static Node getNode(final Node iNode, final String iNodeName)
//package com.java2s; /*/* w w w .j a v a 2 s .com*/ * Copyright (c) [yyyy] [TITULAR] * This file is part of [SSSSS]. * * [SSSS] 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 2 of the License, or * (at your option) any later version. * * This program 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, currently published * at http://www.gnu.org/copyleft/gpl.html or in the gpl.txt in * the root folder of this distribution. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ import org.w3c.dom.*; public class Main { /** * This method returns the desired node which is determined by the * provided node name and namespace. * * @param iNode The provided node structure to be traversed. * @param iNodeName The name of the node being searched for. * * @return Node The desired node. */ public static Node getNode(final Node iNode, final String iNodeName) { Node result = null; if (iNode != null) { // Get the children of the current node NodeList children = iNode.getChildNodes(); // If there are children, loop through the children nodes looking // for the appropriate node if (children != null) { for (int i = 0; i < children.getLength(); i++) { // Get the child node Node currentChild = children.item(i); // Get the current child node's local name String currentChildName = currentChild.getLocalName(); if (currentChildName != null) { // Determine if the current child node is the one that // is being looked for if (currentChildName.equalsIgnoreCase(iNodeName)) { result = currentChild; break; } } } // end looping of children } } // return the resulting vector of nodes return result; } }