Java XML Element Get from Parent getNodeByLocalName(final Node parent, final String name)

Here you can find the source of getNodeByLocalName(final Node parent, final String name)

Description

Return the first node in the given node children which localName matchs the given name.

License

Open Source License

Declaration

public static Node getNodeByLocalName(final Node parent, final String name) 

Method Source Code

//package com.java2s;
/*//w ww  .j  ava 2s  .com
 *    Geotoolkit.org - An Open Source Java GIS Toolkit
 *    http://www.geotoolkit.org
 *
 *    (C) 2010, Geomatys
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation;
 *    version 2.1 of the License.
 *
 *    This library 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
 *    Lesser General Public License for more details.
 */

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

public class Main {
    /**
     * Return the first node in the given node children which localName
     * matchs the given name. Or null if there are no such node.
     */
    public static Node getNodeByLocalName(final Node parent, final String name) {
        if (name.equalsIgnoreCase(parent.getLocalName()))
            return parent;
        final NodeList lst = parent.getChildNodes();

        for (int i = 0, n = lst.getLength(); i < n; i++) {
            final Node child = lst.item(i);
            if (name.equalsIgnoreCase(child.getLocalName())) {
                return child;
            }
        }
        return null;
    }
}

Related

  1. getNamespacePrefix(Node parentNode, String preferredPrefix, String nsUri)
  2. getNameToFirstNode(Node parent, String node_name)
  3. getNameToNodeList(Node parent, String node_name)
  4. getNodeAtPosition(Node parent, int offset)
  5. getNodeBean(Node parent)
  6. getNodeContents(Node parentNode)
  7. getNodeContents(String nodeName, Node parentNode)
  8. getNodeList(Element parent)
  9. getNodes(final Node parent, final String nodeName)