Solved

Help with appending multiple data element from File2.xml to file1.xml

Posted on 2014-02-28
6
308 Views
Last Modified: 2014-02-28
Hi,

Hi,


If file1.xml contains data in Part A in file contains data in Part B. How do append the data from file2 to file 1 and save it as file3.xml?

Part A:

<Root>
<Table1>
<SN>10411</SN>
<NSC>ITEMA</NSC>
</Table1>
<Table1>
<SN>10412</SN>
<NSC>ITEMB</NSC>
</Table1>
<Table1>
<SN>10421</SN>
<NSC>ITEMC</NSC>
</Table1>
<Table1>
<SN>10521</SN>
<NSC>ITEMD</NSC>
</Table1>
<Table1>
<SN>10611</SN>
<NSC>ITEME</NSC>
</Table1>
</Root>


Part B:

<Root>
<Table2>
<RIC><RIC>
<NOP></NOP>
<FIF><FIF>
</Table2>
</Root>

Desired Solution:

File3.xml

<Root>
<Table1>
<SN>10411</SN>
<NSC>ITEMA</NSC>
<RIC><RIC>
<NOP></NOP>
<FIF><FIF>
</Table1>
<Table1>
<SN>10412</SN>
<NSC>ITEMB</NSC>
<RIC><RIC>
<NOP></NOP>
<FIF><FIF>
</Table1>
<Table1>
<SN>10421</SN>
<NSC>ITEMC</NSC>
<RIC><RIC>
<NOP></NOP>
<FIF><FIF>
</Table1>
<Table1>
<SN>10521</SN>
<NSC>ITEMD</NSC>
<RIC><RIC>
<NOP></NOP>
<FIF><FIF>
</Table1>
<Table1>
<SN>10611</SN>
<NSC>ITEME</NSC>
<RIC><RIC>
<NOP></NOP>
<FIF><FIF>
</Table1>
</Root>

Thanks,

Victor
0
Comment
Question by:vcharles
  • 3
  • 3
6 Comments
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
Hi Victor;

In your example you change the parent node Table2 to Table1 and add that as the first child node under the root node, is that what you want?

In the Part B is the parent node always going to be Table2 and in Part A will it always be Table1?
0
 

Author Comment

by:vcharles
Comment Utility
Hi,

Yes to both of your questions. The table names are not very important just using thoses as examples, will use different ones in my project. Many goal is to append the data from file2.xml to all the records in file1.xml.

Thanks,

Victor
0
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
Comment Utility
Hi Victor;

See if this is what you are looking for.

' Open the two XML documents
Dim file1Xml = XDocument.Load("C:\Working Directory\file1.xml")
Dim file2Xml = XDocument.Load("C:\Working Directory\file2.xml")

' Get the nodes to be appended to the elements of file1.xml
Dim file2Elements = From f2 In file2Xml.Descendants("Table2").Elements()
                    Select f2
' Get the modes to be appended too.
Dim file3Xml = From f1 In file1Xml.Descendants("Table1")
               Select f1
               
' Append the nodes               
For Each node In file3Xml
   node.Add(file2Elements)
Next

' Save as file3.xml
file1Xml.Save("C:\Working Directory\File3.xml")

Open in new window

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:vcharles
Comment Utility
Hi,

On my way home, will test it as soon as I get home and get back to you.

Thanks,

Victor
0
 

Author Comment

by:vcharles
Comment Utility
Hi,

It works.

Thanks,

Victor
0
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
Not a problem Victor, glad to help.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now