Solved

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

Posted on 2014-02-28
6
317 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 63

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 63

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
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 

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 63

Expert Comment

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

Featured Post

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

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

Suggested Solutions

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

759 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