Java Utililty Methods XML Node Path

List of utility methods to do XML Node Path

Description

The list of methods to do XML Node Path are organized into topic(s).

Method

StringgetIndividualPath(Node individual)
get Individual Path
String target_source = "";
String file_name = "";
if (individual != null) {
    target_source = individual.getAttributes().getNamedItem("location").getNodeValue();
    file_name = individual.getAttributes().getNamedItem("file").getNodeValue();
    return target_source + file_name;
return null;
...
voidgetMatchingNodes(Node node, String[] nodePath, int cur, List res)
get Matching Nodes
if (cur < 0 || cur >= nodePath.length)
    return;
boolean last = (cur == nodePath.length - 1);
String name = nodePath[cur];
if (node.hasChildNodes()) {
    NodeList children = node.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node c = children.item(i);
...
NodegetNode(Node node, String... nodePath)
get Node
List<Node> nodes = getNodes(node, nodePath);
if (nodes != null && nodes.size() > 0) {
    return nodes.get(0);
} else {
    return null;
NodegetNode(Node root, String nodePath)
get Node
String[] nodePathArr = nodePath.split("/");
return getNode(root, nodePathArr, 0);
StringgetNodeCompletePath(Node node)
get Node Complete Path
Node cur, tmp, next;
String buffer = "";
String sep;
String name;
int occur = 0;
boolean generic;
cur = node;
do {
...
String[]getNodePath(Node node)
get Node Path
Deque<String> list = new LinkedList<String>();
list.addFirst(node.getNodeName());
node = node.getParentNode();
while (node != null) {
    list.addFirst(node.getNodeName());
    node = node.getParentNode();
return list.toArray(new String[0]);
...
StringgetNodePath(Node node)
get Node Path
StringBuilder buffer = new StringBuilder("/");
Stack<String> stack = new Stack<String>();
Node n = node;
while (n != null) {
    String nname = n.getNodeName();
    NamedNodeMap attrs = n.getAttributes();
    if (attrs != null && attrs.getLength() != 0) {
        Node attr = attrs.getNamedItem("xconf-uid");
...
StringgetNodePath(Node node)
get Node Path
StringBuffer sb = new StringBuffer(32);
while (node != null) {
    sb.append(node.getNodeName());
    sb.append("/");
    node = node.getParentNode();
return sb.toString();
StringgetNodePath(Node node, String postfix)
get Node Path
if (node.getParentNode() != null) {
    return getNodePath(node.getParentNode(), node.getParentNode().getNodeName() + "/" + postfix);
} else {
    return postfix;
ListgetNodes(Node node, String path)
get Nodes
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]);
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;