Use Xml to create a tree?

Hi all,

I am trying to save and read back a tree like this:

a  - b  - c  - d  - e  - f  - g  - h                     // main branch
               d2 - e2 - f2 - g2                         // branch 2
                         f3 - g3 - h3 - i3 - l3 - m3     //branch 3

I was thinking of using xml for this but I am not sure it’s the best tool for the job. I could make b child of a, c child of b, d and d2 child of c, etc… but how to navigate the tree efficiently? I try to explain.

The tree will be associated to a Canvas which will show its content just like in code block above. If the user clicks on e2, for example, he could add data to that branch, that is f2, or create a new branch, that is f3. It means that when the user clicks on e2 I have to move to that particular node of the xml. How to do it efficiently?

Is there any better option than xml?

I hope my question is clear.

Thanks,
Davide.

Stupid question: where is the tree? This looks more like a graph.

<a> <d2> <f3></f3> <g3></g3> ...... </d2> <e2> <f3></f3> <g3></g3> ...... </e2> ...... </a> <b> <d2> <f3></f3> <g3></g3> ...... </d2> <e2> <f3></f3> <g3></g3> ...... </e2> ...... </b>
A similar thing ?

XML is a tree structure by nature, so it should work for what you want. You would have to associate an XMLNode with each “object” on the canvas, but that shouldn’t be too difficult. When you click on an object in the canvas, you get an XMLNode. At that point, you can operate on its child nodes without concern for where it is in the hierarchy.

You could use a database table.

ID Row Column Value 1 1 1 a 2 1 2 b 3 1 3 c 4 1 4 d 5 1 5 e 6 1 6 f 7 1 7 g 8 1 8 h 9 2 4 d2 10 2 5 e2 11 2 6 f2 12 2 7 g2 13 3 6 f3 14 3 7 g3 15 3 8 h3 16 3 9 i3 17 3 10 l3 18 3 11 m3

Thank you all for the answers.

Interesting. So I could create an array of XmlNode to be associated to the Canvas so that when I click on a specific position of the Canvas I get the corresponding XmlNode. Does it make sense to you? Or there’s something better?

Thanks.