[Expat-discuss] General Purpose Tree to Hold Things (Help and Hints Please)

Chris Garrity m0ntar3@home.com
Thu, 12 Jul 2001 04:52:07 -0500


	I've started to write some general purpose routines to build a tree from an XML
document, in straight C.

	I've defined a node-structure to hold a tag name, text, and an attribute list.
I set the tag and attribute list fields in my start-tag handler, and then I push
the node onto a stack that I've defined. In my text handler, I peek at the node
on top of the stack, return a pointer to it, and add text to the text field. In
the end-tag handler, I pop the stack and insert into a tree. The tree node I
create at this point holds the depth (from within the document) of the current
tag.

	The tree I've defined is an N-ary tree, with each node having a pointer to it's
child and to a list of it's siblings. Implementing a proper insertion algorithm
is what I'm working on currently.

	Basically, while the depth of the new tree node is greater than the current
node, I descend. When the depth of the new tree node is equal to the current
node, I traverse across the list of siblings. The problem I see with this is
that the new tree node well not always be a descendant of the first tree node at
depth N. I figure I can pass the tag name of the parent along with the new tree
node,  and then know how far over to traverse the list of siblings.

	C++ is not a really an option in the current environment I'm working in, so
that's not a solution presently (no STL solution).

	Comments?