Can I append one dom to another?
Hi,
I have created two DOM objects from separate source.
But I want to merge them into one DOM.
How can I do this task?
Thanks for your answer!
Imju
[178 byte] By [
Imju Byon] at [2007-11-9 15:27:27]

# 1 Re: Can I append one dom to another?
Create a 3rd DOM, something like this:
oDOM3.loadXML("<BothDOMs></BothDOMs>")
Set oRootNode = oDOM3.documentElement
oRootNode.appendchild oDOM1.documentElement
oRootNode.appendchild oDOM2.documentElement
oDOM3.save("bothdocs.xml")
Lou at 2007-11-11 23:29:47 >

# 2 Re: Can I append one dom to another?
Did you try it? Are you having a specific problem? Here's an example that
merges data from two existing XML files into a new document using the .NET
XmlDocument's ImportNode(node) method. The first parameter is the node you
want to import, the second is whether the import should be a "deep" copy
(children and all) or a shallow copy (just the target node). The example
code below is in VB.NET.
Dim doc1 As New XmlDocument()
Dim doc2 As New XmlDocument()
Dim doc3 As New XmlDocument()
Dim N As XmlNode
Dim NParent As XmlNode
doc1.Load("some xml file here")
doc2.Load("some xml file here")
' create a new XML document to contain the merged documents
doc3.LoadXml("<?xml version=""1.0""?><all/>")
' import the first document and append it to the <all> element in doc3
N = doc3.ImportNode(doc1.DocumentElement, True)
doc3.DocumentElement.AppendChild(N)
' import the second document and append it to the <all> element in
doc3
N = doc3.ImportNode(doc2.DocumentElement, True)
doc3.DocumentElement.AppendChild(N)
' save the results
doc3.Save("some xml filename here")
You can create such merged documents using XSLT as well. Search Google for
"merging xml documents" and you'll get a number of useful articles.
"Lou" <l_kvitek@audiblemagic.com> wrote in message
news:3dfe7350$1@tnews.web.dev-archive.com...
>
> Create a 3rd DOM, something like this:
>
> oDOM3.loadXML("<BothDOMs></BothDOMs>")
> Set oRootNode = oDOM3.documentElement
>
> oRootNode.appendchild oDOM1.documentElement
> oRootNode.appendchild oDOM2.documentElement
>
> oDOM3.save("bothdocs.xml")
>