Question:
Is there an easy and efficient way to insert an XML document into another XML template? The insertion point can be before, between, or after specified nodes.
Answer:
Sure. I do this all the time. If you’re going from a DOM-based solution, you can incorporate one XML structure into another through the use of appendChild and cloneNode. For example:
dim parentDocdim childDocdim insertionNodeset parentDoc=createObject("Microsoft.XMLDOM")set childDoc=createObject("Microsoft.XMLDOM")parentDoc.load "myXMLDoc.xml"childDoc.load "myChildXMLDoc.xml"set insertionNode=parentDoc.selectSingleNode("//some/arbitrary/path")insertionNode.appendChild childDoc.documentElement
In this case, you load in two documents, select the node you want to attach the child document to, then append the document element of the child document as a child to that node. There is similarly an .insertBefore(nodePos) method that can insert the new document into the node along with any other children that the node happens to have.