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

Allen, Michael B (RSCH) Michael_B_Allen@ml.com
Thu, 12 Jul 2001 18:00:37 -0400


Well, I'm not really sure I understand what your immediate problems are but you do know about DOM right? The Document Object Model it the W3C recommended way to build and manipulate a tree data
structure representing an XML (or possibly HTML) document.

http://www.w3.org/DOM/

There are already several implementations in c. There's one by Oracle and Gnome's Gdome but I don't think Oracle's is usable for commercial perposes and there certainly isn't any source code and Gdome
uses a C++ in c technique that is a little more sophisticated than I need(20000 lines of code).

Incedentally I have recently started to implement a comparatively light weight DOM in c (the target is more like 2000 lines of code).

http://auditorymodels.org/domc/

but this code doesn't work and I have already practially rewritten it entirely. I will post a new batch by the end of this weekend but I suspect it too will be unusable. I don't plan on spending more
than two weeks or so on this though.

Mike

> -----Original Message-----
> From:	Chris Garrity [SMTP:m0ntar3@home.com]
> Sent:	Thursday, July 12, 2001 5:52 AM
> To:	expat-discuss@lists.sourceforge.net
> Subject:	[Expat-discuss] General Purpose Tree to Hold Things (Help and Hints Please)
> 
> 
> 	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?
> 
> _______________________________________________
> Expat-discuss mailing list
> Expat-discuss@lists.sourceforge.net
> http://lists.sourceforge.net/lists/listinfo/expat-discuss