Solved

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

Posted on 2014-02-28
6
318 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
Use Filtering Commands to Process Files in Linux

Learn how to manipulate data with the help of various filtering commands such as `cat`, `fmt`, `pr`, and others in Linux.

 

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

622 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