With recursive XML, you should think about using recursion! Generally, this means a function that calls itself. Pass an xml object in and create nodes up the tree, returning either a call further up the tree or the XML element created in that node.
Hard to say exactly how without more info on what you're doing, but recursion truly is the answer. Now, something I noticed from your XML example, XML should describe the data. Typically, your data is not row/cell unless it's generic enough to use WDDX instead of what you're doing. For example, in HTML, we don't say <element>Welcome...</element>, we describe the data with an H1 tag: <h1>Welcome...</h1>. Likewise, your XML should describe your data. If your XML schema is generic enough to warrant <rows>, <row> and <cell> tag usage, do strongly consider switching to just using wddx to serialize a tree of structs, arrays or database queries. Eh ok, just an outsider's view in. ignore if you feel like it. -- nathan strutz http://www.dopefly.com/ On 11/6/07, Richard White <[EMAIL PROTECTED]> wrote: > > Hi, > > we are trying to build an xml document that will be used to build a tree > (like the explorer tree in windows). it could be an infinite number of rows > deep and we are trying to build it recursively through code from data out of > a database. > > the problem we are having is trying to uniquely reference each element. > for example we are trying to simply build the following: > > <rows> > <row id="tb_1"> > <cell image="onetoonefolder.gif">Once per Subject</cell> > </row> > </rows> > > at present the code we are using to get this is: > > MyDoc = XmlNew(); > MyDoc.xmlRoot = XmlElemNew(MyDoc,"rows"); > > MyDoc.rows.XmlChildren[1] = XmlElemNew(MyDoc, "row"); > MyDoc.rows.XmlChildren[1].XmlAttributes.id = "tb_1"; > > MyDoc.rows.XmlChildren[1].XmlChildren[1] = XmlElemNew(MyDoc, "cell"); > MyDoc.rows.XmlChildren[1].XmlChildren[1].XmlAttributes.image = " > onetoonefolder.gif"; > MyDoc.rows.XmlChildren[1].XmlChildren[1].XmlText = "Once per Subject"; > > Of course you can see that this is not efficient as if we want to go an > infinite amount of levels deep we cannot keep writing: > > XmlChildren[1].XmlChildren[1].XmlChildren[1].XmlChildren[1] etc... > > we realise that this must go in a loop but was wondering how we can > uniquely name each element and then how do we reference that in a loop. > > Thanks very much for your help > > richard > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Check out the new features and enhancements in the latest product release - download the "What's New PDF" now http://download.macromedia.com/pub/labs/coldfusion/cf8_beta_whatsnew_052907.pdf Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:292785 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

