Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Bulding an index into a xml document

Moderators: larsivi kris

Posted: 05/14/09 06:53:58

I have a xml document where elements have id attributes attached, these simply start counting from 1. Much like a relational database, these id's reference other nodes. I need to do a lot of loopups based on these id's, it would be very convenient to make a lookup table as an array containing pointers to the nodes of the xml document.

Is this possible with Tango and how?

I hope I made myself clear enough.


Author Message

Posted: 05/14/09 08:02:24

Certainly. You could walk the DOM tree, inspecting the nodes as you go, or you could use the XPath lookups to isolate a set of elements with id's in them, or a combination of both. Could place the resulting node references into your index, and everything should work nicely.

Note that document nodes are not garbage collected until the document is disposed of.

Posted: 05/14/09 18:53:45 -- Modified: 05/21/09 10:08:03 by

Cool. Using XmlPath? I should .dup the queries right? Is this not needed when iterating the dom or fetching nodes from the queries?

For example, if I use .elements or .root on a document, then iterate the whole tree whilst tucking away interesting nodes in an array, I will be fine?


EDIT: I figured it out, this stuff works like a charm and it's fast too!

Posted: 05/21/09 21:35:17