Here you can find the source of findTreeNodeWithXmlPath(DefaultMutableTreeNode treeNode, String nodeXmlPath)
public static DefaultMutableTreeNode findTreeNodeWithXmlPath(DefaultMutableTreeNode treeNode, String nodeXmlPath)
//package com.java2s; /*L//from w ww . j a v a 2s .c o m * Copyright SAIC, SAIC-Frederick. * * Distributed under the OSI-approved BSD 3-Clause License. * See http://ncip.github.com/caadapter/LICENSE.txt for details. */ import javax.swing.tree.DefaultMutableTreeNode; import java.util.StringTokenizer; public class Main { public static DefaultMutableTreeNode findTreeNodeWithXmlPath(DefaultMutableTreeNode treeNode, String nodeXmlPath) { if (nodeXmlPath == null) { System.out.println("UIHelper.findTreeNodeWithXmlPath()..invalid node to search:" + nodeXmlPath); return null; } StringTokenizer st = new StringTokenizer(nodeXmlPath, "/@"); boolean foundRoot = false; DefaultMutableTreeNode e = treeNode; while (st.hasMoreTokens() && e != null) { String tmp = st.nextToken(); if (!foundRoot) { if (e.toString().equals(tmp)) { foundRoot = true; continue; } else continue; } else { int childCount = e.getChildCount(); DefaultMutableTreeNode found = null; for (int i = 0; i < childCount; i++) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) e.getChildAt(i); if (child.toString().equals(tmp)) { found = child; break; } } if (found == null) { return null; } else { e = found; } } } if (!foundRoot) return null; return e; } }