From: Marc P. <ma...@an...> - 2003-04-21 13:14:44
|
Ah, a fresh new thread :-) OK from Brian's extremely helpful discussion on this issue already, I think we can now narrow the problem space into two sections. I would like to add that at this point I think it is helpful to remember that we are not just discussing XML usage here - we should consider any tree structure - although XML is the most prevalent example that springs to mind. Problem 1. Accessing sections (branches) of a tree structure and rendering information from them. Pre-requisites: Knowing the structure of the tree in advance (which types of nodes are children of others), and which types of nodes you want to get access to. Problem 2. Displaying an entire tree, in a strict order (t-d/l-r or l-r/t-d depending on the data structure). Pre-requisite: You wish to visit all nodes in the tree. These are in effect completely different scenarios. Problem 1 requires a helper class with the ability to select nodes and return them flattened in a list, or a WM-supplied selection mechanism that can work on any kind of node object using introspection to work out if the node complies with the search criteria. The latter being far too specific usage for WM I think, but in a way it would be very cool - #foreachnode $varname [topdown | leftright] [filtering (expr)]: #foreachnode $node in $mytreeData topdown filtering ( $node.IsText && ($node.Parent.Name == "description")) $node.Value #end I suspect nobody will like that idea though. For XML-specific usage it would be nicer with the expression using XPath or similar syntax: #foreachnode $node in $mytreeData topdown filtering "parent::description/text()" $node.Value #end ...or something like that anyway, but that is an XML specific solution - which I am not interested in. Problem 2 can either be solved by having a helper class that can return ALL nodes flattened, or by a similar tree iteration mechanism. Flattening a whole tree is often easy enough - and in fact in my current XML problem scenario we have a method to do this - but it is really rather wasteful of memory and processing. Yes you can cache the results, but it seems a little crazy to take a perfectly good tree structure and transfer it into an array with potentially thousands of elements, just to display it. So, any other ideas on how to solve these two problems elegantly would be much appreciated. You poor guys who aren't reading your email over Easter... Brian and I have been mailbombin you :-( -- Marc Palmer (Wangjammer5) http://www.wangjammers.org Java Consultants |