Java XML Node Path getNode(Node root, String nodePath)

Here you can find the source of getNode(Node root, String nodePath)

Description

get Node

License

Open Source License

Declaration

static Node getNode(Node root, String nodePath) 

Method Source Code

//package com.java2s;
/**//from ww w  . ja v a  2  s . c om
 * Copyright (c) 2010-2019 Contributors to the openHAB project
 *
 * See the NOTICE file(s) distributed with this work for additional
 * information.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0
 *
 * SPDX-License-Identifier: EPL-2.0
 */

import org.w3c.dom.Element;
import org.w3c.dom.Node;

public class Main {
    static Node getNode(Node parent, String[] nodePath, int offset) {
        if (parent == null) {
            return null;
        }
        if (offset < nodePath.length - 1) {
            return getNode(((Element) parent).getElementsByTagName(nodePath[offset]).item(0), nodePath, offset + 1);
        } else {
            return ((Element) parent).getElementsByTagName(nodePath[offset]).item(0);
        }
    }

    static Node getNode(Node root, String nodePath) {
        String[] nodePathArr = nodePath.split("/");
        return getNode(root, nodePathArr, 0);
    }
}

Related

  1. getElementViaPath(Node node, String path)
  2. getFullPath(Node node)
  3. getIndividualPath(Node individual)
  4. getMatchingNodes(Node node, String[] nodePath, int cur, List res)
  5. getNode(Node node, String... nodePath)
  6. getNodeCompletePath(Node node)
  7. getNodePath(Node node)
  8. getNodePath(Node node)
  9. getNodePath(Node node)