Here you can find the source of getNodes(Node node, String path)
Parameter | Description |
---|---|
node | a parameter |
path | a parameter |
public static List<Node> getNodes(Node node, String path)
//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; } }