Java XML Node Find findElementByName(Node node, final String name)

Here you can find the source of findElementByName(Node node, final String name)

Description

Look for Element node of given name.

License

Open Source License

Parameter

Parameter Description
node Node where to start.
name Name of the node to look for.

Return

Returns node, the next matching sibling, or null.

Declaration

private static final Element findElementByName(Node node, final String name) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2015-2016 Oak Ridge National Laboratory.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/

import org.w3c.dom.Element;

import org.w3c.dom.Node;

public class Main {
    /** Look for Element node of given name.
     */*from   w w  w.  ja  v  a2 s .  c  o  m*/
     *  <p>Checks the node itself and its siblings for an {@link Element}.
     *  Does not descent down the 'child' links.
     *
     *  @param node Node where to start.
     *  @param name Name of the node to look for.
     *  @return Returns node, the next matching sibling, or <code>null</code>.
     */
    private static final Element findElementByName(Node node, final String name) {
        while (node != null) {
            if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals(name))
                return (Element) node;
            node = node.getNextSibling();
        }
        return null;
    }
}

Related

  1. findAllUrisRecursive(Node node, List nodes)
  2. findElement(Node node, String tagName)
  3. findElement(Node startNode, String name, String namespace)
  4. findElementById(Node head, String id)
  5. findElementById(Node node, String id)
  6. findElementByTag(Set nodes, String tag)
  7. findElementNodeByName(Node node, String name)
  8. findElements(Node fromnode, String name)
  9. findElementsByName(Node node, List elements, String name)