Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: XML
Expertise: Beginner
Jan 21, 2000

Insert XML Into Another XML Document

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 parentDoc
dim childDoc
dim insertionNode
set 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.

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap