Java XML Node Path getNodes(Node node, String path)

Here you can find the source of getNodes(Node node, String path)

Description

get Nodes

License

Open Source License

Parameter

Parameter Description
node a parameter
path a parameter

Declaration

public static List<Node> getNodes(Node node, String path) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;
import java.util.List;

import org.w3c.dom.Node;

public class Main {

    public static List<Node> getNodes(Node node, String path) {
        ArrayList nodeList = new ArrayList();

        ArrayList pathList = new ArrayList();
        String[] pathArray = path.split("/");
        for (int i = 0; i < pathArray.length; i++) {
            if (pathArray[i].equals(""))
                continue;
            pathList.add(pathArray[i]);/*from  ww w.  j  av  a2s .  c om*/
        }

        for (int i = 0; i < pathList.size(); i++) {
            StringBuffer restPath = new StringBuffer();
            for (int k = i + 1; k < pathList.size(); k++) {
                restPath.append("/").append((String) pathList.get(k));
            }

            for (int j = 0; j < node.getChildNodes().getLength(); j++) {
                if (!node.getChildNodes().item(j).getNodeName().equals(pathList.get(i)))
                    continue;
                if (restPath.length() == 0) {
                    nodeList.add(node.getChildNodes().item(j));
                } else {
                    nodeList.addAll(getNodes(node.getChildNodes().item(j), restPath.toString()));
                }
            }

        }

        return nodeList;
    }
}

Related

  1. getNodeCompletePath(Node node)
  2. getNodePath(Node node)
  3. getNodePath(Node node)
  4. getNodePath(Node node)
  5. getNodePath(Node node, String postfix)
  6. getNodesPathName(Node node)
  7. getNXInfo(Node xmlDoc, String NXclassPath, String NXclassNameList, String fieldName, String filename)
  8. getNXInfo1(Node xmlDoc, String NXclassPath, String NXclassNameList, String fieldName, String filename)
  9. getNXInfoDefault(Node xmlDoc, String NXclassPath, String NXclassNameList, String fieldName, String filename)