on 05-25-2006 3:52 PM
Dear All,
I want to display the Texonomy tree structure as displayed in the Data Manager for a taxonomy table.I am using the following code to get the parent node and children :
WebTreeNode wtn = catalog.GetHierarchy("<taxonomy table name>",<node ID>); (node ID:0 for root)
WebTreeNodeArray wtna = wtn.GetChildren();
Then I want to loop through the array to get each child node and subsequently for other sub nodes till i reach the leaf nodes.
However the problem is that the tree structure does not follow a fixed pattern , meaning to say that each node may have 0 to n child nodes.I can't figure out a logic to put all the nodes under one parent inside a List and then probably put them into a Map with name of the parent as Key.If anybody can help to device the (recursion)logic , i'll be thankful.
hi Karambir.
Sorry i have forgotten to give u printSpaces()
Here is the method code.
private static void printSpaces(int n) {
for (int i = 0; i < n; i++) {
System.out.print(' ');
}
}
Regards .
Brahmanndam Ausali
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Karambir.
try following method which displays the tree.
public void listChildren(WebTreeNode webtreenode, int depth)
{
printSpaces(depth);
System.out.println(webtreenode.GetValue());
WebTreeNodeArray webtreenodearray = webtreenode.GetChildren();
for(int i = 0 ; i< webtreenodearray.GetCount();i++)
{
WebTreeNode child = webtreenodearray.GetWebTreeNodeAt(i);
listChildren(child, depth+1);
}
}
This is a recursive method, pass node and depth frome where you want to display. The values will be displayed in tree fornat.
try this and let me know if there are any issues.
Regards
Brahmanandam Ausali
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Karambir,
public void displayHierarchyData()throws Exception
{
WebTreeNode wt = catalog.GetHierarchy(<Hierarchy/Taxnomy Table Name>,0);
WebTreeNodeArray nodeArray = wt.GetChildren();
for(int i=0;i<nodeArray.GetSize();i++)
{
WebTreeNode childNode = nodeArray.GetWebTreeNodeAt(i);
System.out.println(childNode.GetValue());
drillDownWebTree(childNode);
}
}
public void drillDownWebTree(WebTreeNode childNode)
{
WebTreeNodeArray nodeArray = childNode.GetChildren();
if(nodeArray.GetSize()>0)
{
for(int i=0;i<nodeArray.GetSize();i++)
{
WebTreeNode innerChildNode = nodeArray.GetWebTreeNodeAt(i);
if(innerChildNode.GetChildren().GetSize()>0)
{
System.out.println("->" + innerChildNode.GetValue());
drillDownWebTree(innerChildNode);
}
else
{
System.out.println("-->"+innerChildNode.GetValue());
}
}
}
}
Hope this helps.
Thanks and Regards
Subbu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.