Java XML Node Name getNode(Node iNode, String iNodeName)

Here you can find the source of getNode(Node iNode, String iNodeName)

Description

This method returns the desired node which is determined by the provided node name and namespace.

License

Open Source License

Parameter

Parameter Description
iNode The provided node structure to be traversed.
iNodeName The name of the node being searched for.

Return

Returns the desired node.

Declaration

public static Node getNode(Node iNode, String iNodeName) 

Method Source Code

//package com.java2s;
/* Agrega es una federaci?n de repositorios de objetos digitales educativos formada por todas las Comunidades Aut?nomas propiedad de Red.es. Este c?digo ha sido desarrollado por la Entidad P?blica Empresarial red.es adscrita al Ministerio de Industria,Turismo y Comercio a trav?s de la Secretar?a de Estado de Telecomunicaciones y para la Sociedad de la Informaci?n, dentro del Programa Internet en el Aula, que se encuadra dentro de las actuaciones previstas en el Plan Avanza (Plan 2006-2010 para el desarrollo de la Sociedad de la Informaci?n y de Convergencia con Europa y entre Comunidades Aut?nomas y Ciudades Aut?nomas) y ha sido cofinanciado con fondos FEDER del Programa Operativo FEDER 2000-2006 ?Sociedad de la Informaci?n?
    //from   w w w . j av a 2s .c o  m
This program is free software: you can redistribute it and/or modify it under the terms of the European Union Public Licence (EUPL v.1.0).  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 European Union Public Licence (EUPL v.1.0). You should have received a copy of the EUPL licence along with this program.  If not, see http://ec.europa.eu/idabc/en/document/7330.
*/

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

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 Returns the desired node.
     */
    public static Node getNode(Node iNode, 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;
    }
}

Related

  1. getName(Node node)
  2. getName(Node node)
  3. getName(Node node)
  4. getNode(final Node iNode, final String iNodeName)
  5. getNode(Node iNode, String iNodeName)
  6. getNode(Node node, String nodeName)
  7. getNode(Node node, String nodeName)
  8. getNodeContent(Node item, String nodeName)
  9. getNodeContent(Node n, String nodename)