I have a class in which there is a print method to print the output.the code is given below.

public class class1
{
public void printNode(TreeNode root, string tabs)
        {


       string rootnode;
       string childnodes;

            rootnode = tabs + "| " + root.attribute + "|" + ":";

          

            StringBuilder sb = new StringBuilder();
            if (root.attribute.values != null)
            {

                for (int i = 0; i < root.attribute.values.Length; i++)
                {
                    sb.Append(tabs + "\t" + "<" + root.attribute.values[i] + ">");

                    // Console.Write(tabs + "\t" + "<" + root.attribute.values[i] + ">");

                    TreeNode childNode = root.getChildByBranchName(root.attribute.values[i]);
                    printNode(childNode, "\t" + tabs);
                }
            }
            childnodes = sb.ToString();
        }

}
I called this method in a web page like this;
class1 cls =new class1();

cls.printNode(root,"");

but problem is that output is not getting displayed.

Instead of using rootnode and childnodes as string, is there any other way to display the text and then call to the web page.


please help me...Its urgent...I am behind on this for so many days...please...

printNode is a recursive function... there might be another problem, but the follow is definitely an issue:

when printNode is called for the childnodes, it is instantiating a new StringBuilder each time. In other words, you are creating an object per node and not one StringBuilder for the whole tree.. i guess stringbuilder should be an object promoted outside the method.. should be placed in the class.

try that

..or promote childnodes and rootnodes to private in class... not sure how you intend to print the text

sir,
nothing is getting displayed.I tried your suggestion.Can we use instead of string,some arraylist,or any other control to store the values and then display in the web pages by calling the print method.
I am a beginner only.But i have timelimit..within one week..Please help me if any one knows this

my intention to print text is like this;


|climate|
<dry climate>
|humidity|
<low humidity>
|don't play|


like this i want the output based on the user inputs,ie the no. of attributes it has to be printed recursively.

..or promote childnodes and rootnodes to private in class... not sure how you intend to print the text

sir,
nothing is getting displayed.I tried your suggestion.Can we use instead of string,some arraylist,or any other control to store the values and then display in the web pages by calling the print method.
I am a beginner only.But i have timelimit..within one week..Please help me

I will give an example;

suppose data is;

humidity---low and high
climate---dry and rainy
play---yes and no


I have to print ouput like this;


|humidity|
<low>
|climate|
<dry>
|yes|

How can i get it.Those people who know this, please help me.

I just tried the following and worked OK:

private void StartHere()
        {
            foreach (TreeNode node in YourTreeView.Nodes)
            {
                ListNodes(node);
            }
        }

        private void ListNodes(TreeNode node)
        {            
            // Write text from your first node
            sb.Append(node.Text + "|" + Environment.NewLine);

            // for each child node within node, do recursive 
            foreach (TreeNode subnode in node.Nodes)
            {
                ListNodes(subnode);
            }
        }

p.s.

please do not forget to mark as solved

thanks

Hi sir, Thanks for your reply. There is one problem. I am using Id3 algorithm in data mining to select which string value will come in each node.

There is one calculated measure in that,based on that only we will decide which value will go to which node.So root node also can be any of the values and the coming nodes will come only from the remaining values.
If you have doubt,the link on an article of Id3 is given below.tha algorithm is easy.But how to show its output is the problem

www.cise.ufl.edu/~ddd/cap6635/Fall-97/Short.../2.htm

I tried to use your code.But then giving values to the nodes is becoming a problem.

What to do now.

i cant understand you... the values of the nodes are unimportant. Also, that link will not work unless you're logged in

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.