Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > Pro VB.NET 2002/2003
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Pro VB.NET 2002/2003 For advanced Visual Basic coders working .NET version 2002/2003. Beginning-level questions will be redirected to other forums, including Beginning VB.NET.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 15th, 2006, 09:48 AM
Authorized User
 
Join Date: Jun 2006
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to merge two xml documents 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



Reply With Quote
  #2 (permalink)  
Old June 15th, 2006, 04:03 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

I think you are just going to have to walk the nodes, and be more rudimentary about it.
Is there an .AppendNode method that is the functional equivalent of .AppendChild? It looks as if (if there is such a creature) that would do the trick in the specific example you gave.
Reply With Quote
  #3 (permalink)  
Old August 22nd, 2008, 05:28 AM
Registered User
 
Join Date: Aug 2008
Location: Auckland, , New Zealand.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Rather than adding the 'DocumentElement' of the second file try something like:

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

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Merge PDF Documents Gyto ASP.NET 2.0 Basics 3 August 19th, 2013 02:33 AM
compare two xml documents bcogney XSLT 1 October 30th, 2006 03:33 PM
merge two xml file and make new xml using xslt ketan XSLT 0 September 21st, 2004 08:48 AM
merge 2 xml documents Beulah VS.NET 2002/2003 0 November 20th, 2003 09:33 PM
Merge XML files into a xml file using xslt lxu XML 4 November 6th, 2003 06:01 PM



All times are GMT -4. The time now is 10:35 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.