tags:

views:

96

answers:

0

Is there a fast way to clear the previous content of an MSXML2.DOMDocument object prior to reuse? I've been in the habit of discarding them and creating a fresh instance each time but this strikes me as wasteful and profiling a few test cases seems to confirm this.

I'm sticking with MSXML 3.0 in this case for portability, and I realize this older version has some quirks when it comes to using XPath to select large sets of nodes. Trying to select the whole document tree and then removing it doesn't feel clean and doesn't run as fast as I'd like. The "lazy selection" MSXML 3.0 uses doesn't inspire confidence either:

selectNodes Method

Previously, in MSXML 3.0 and earlier versions, the selection object created by calling the selectNodes method would gradually calculate the node-set. If the DOM tree was modified, while the selectNodes call was still actively iterating its contents, the behavior could potentially change the nodes that were selected or returned. In MSXML 4.0 and later, the node-set result is fully calculated at the time of selection. This ensures that the iteration is simple and predictable. In rare instances, this change might impact legacy code written to accommodate previous behavior.

I also realize that reusing such an object requires being mindful of the current settings of different properties (SelectionLanguage, etc.) that might linger between uses. I'd think that shouldn't be a big deal though, especially if the reusage always follows the same pattern.

I suppose what I'm after then is some clean and fast way to clear the loaded DOM to reuse it, or more input as to why reuse might be worse than the alternative of recreation.