Skip to Content
avatar image
Former Member

Getting taxonomy tree structure using MDM Java API

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • avatar image
    Former Member
    May 25, 2006 at 04:53 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 26, 2006 at 04:33 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 26, 2006 at 04:35 AM

    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

    Add comment
    10|10000 characters needed characters exceeded