Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 15th, 2006, 09:45 AM
Authorized User
 
Join Date: Jun 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to merge two xmldocuments together?

Hello guys,

I am trying to merge two xml documents in VB.NET

I have one xmldocument which has the following xml:

<Allocations>
   <Item />
   <Item />
   <Item />
   <Item />
   <Item />
   <Item />
</Allocations>

I have another xml Document which has the following:
<Allocations>
   <Item />
   <Item />
   <Item />
</Allocations>

I want to merge the second xmldocument into the first one.

So I want the following:
<Allocations>
   <Item />
   <Item />
   <Item />
   <Item />
   <Item />
   <Item />
   <Item />
   <Item />
   <Item />
</Allocations>


The way I approaced it is as follows:

The first xmldocument is called: xdoc

The second xmldocument is called: xdoc_Selected

Dim xnodeList As XmlNodeList = xdoc_Selected.SelectNodes("//Allocations/Item")
For Each xnode In xnodeList
  xdoc.AppendChild(xnode)
Next

But this was giving me an error. so I tried this method:

xtempnode = xdoc.ImportNode(xdoc_Selected.DocumentElement, True)
xdoc.DocumentElement.AppendChild(xtempnode)

But this results in the following xml:

<Allocations>
   <Item />
   <Item />
   <Item />
   <Item />
   <Item />
   <Item />
   <Allocations>
       <Item />
       <Item />
       <Item />
   </Allocations>
</Allocations>

By the way, I DO NOT want to load the two xml's into a DataSet and then merge them. I want to do it without DataSet. Please advice me on what I am doing wrong. Thank you.

Sanch



 
Old June 15th, 2006, 12:59 PM
Authorized User
 
Join Date: Jun 2006
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The simple algorithm that can be used to do this is . Get the oot element of the First document . Remove the corresponding ending element from the first document . Now get the Second document and remove the root element ( I assume that the root element of both the first and the second document are the same , if not than this procedure may not be followed and the two files can be appended one after the other ) , now appened the second file directly to the first file . Now u have both the XML files in one single doc . U can further process this file in whichever way u want .






Similar Threads
Thread Thread Starter Forum Replies Last Post
Multitiff merge nanjundakl C# 0 November 24th, 2006 12:22 AM
Whether or not to merge two tables chrislepingwell SQL Language 1 November 24th, 2005 06:18 PM
Need Help In Mail Merge raghur Access VBA 0 September 8th, 2005 05:46 AM
How do I merge these two codes? stacy Classic ASP Databases 1 March 22nd, 2004 04:30 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.