Solved

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

Posted on 2014-02-28
6
315 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
ID: 39895870
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
ID: 39895942
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
ID: 39895979
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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:vcharles
ID: 39896038
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
ID: 39896471
Hi,

It works.

Thanks,

Victor
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 39896629
Not a problem Victor, glad to help.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

785 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