Victor Charles
asked on
Help with appending data from file2 to file1 using VB.NET
Hi,
How do I modify the code below to avoid appending a data element from file2 to file1 if it already exit in file1?
Dim f1 = XDocument.Load(Application .StartupPa th + "\fil1.xml")
Dim f2 = XDocument.Load(Application .StartupPa th + "\fil2.xml")
Dim elements As List(Of XElement) = (From n In f2.Descendants("tabl2") _
From c In n.Elements() _
Select c).ToList()
Dim tables As List(Of XElement) = (From t In f1.Descendants("table1") _
Select t).ToList()
For Each table As XElement In tables
For Each element As XElement In elements
table.Add(element)
Next
Next
f1.Save(Application.Startu pPath + "\file3.xml")
Thanks,
Victor
How do I modify the code below to avoid appending a data element from file2 to file1 if it already exit in file1?
Dim f1 = XDocument.Load(Application
Dim f2 = XDocument.Load(Application
Dim elements As List(Of XElement) = (From n In f2.Descendants("tabl2") _
From c In n.Elements() _
Select c).ToList()
Dim tables As List(Of XElement) = (From t In f1.Descendants("table1") _
Select t).ToList()
For Each table As XElement In tables
For Each element As XElement In elements
table.Add(element)
Next
Next
f1.Save(Application.Startu
Thanks,
Victor
ASKER
Hi,
If file1.xml contains data in Part A and file2.xml data in Part B, I want the code to create the file in Part C by copying data elements from file2.xml to file1.xml when not available in file1.
Part A:
file1.xml
<Root>
<table1>
<ID><I</ID>
<AGD>11</AGD>
<SNN>12</SNN>
</table1>
<table1>
<ID>2</ID>
<SNN>12b</SNN>
<NSC>13b</NSC>
</table1>
<table1>
<ID>3</ID>
<AGD>11c</AGD>
<SNN>12c</SNN>
<NSC>13c</NSC>
</table1>
</Root>
Part B:
file2.xml
<Root>
<table2>
<ID>1</ID>
<NSC></NSC>
<AGD></AGD>
<SNN></SNN>
<THY></THY>
Part C:
file3.xml
<Root>
<table1>
<ID><I</ID>
<AGD>11</AGD>
<SNN>12</SNN>
<NSC></NSC>
<THY></THY>
</table1>
<table1>
<ID>2</ID>
<AGD></AGD>
<SNN>12b</SNN>
<NSC>13b</NSC>
<THY></THY>
</table1>
<table1>
<ID>3</ID>
<AGD>11c</AGD>
<SNN>12c</SNN>
<NSC>13c</NSC>
<THY></THY>
</table1>
</Root>
Thanks,
Victor
If file1.xml contains data in Part A and file2.xml data in Part B, I want the code to create the file in Part C by copying data elements from file2.xml to file1.xml when not available in file1.
Part A:
file1.xml
<Root>
<table1>
<ID><I</ID>
<AGD>11</AGD>
<SNN>12</SNN>
</table1>
<table1>
<ID>2</ID>
<SNN>12b</SNN>
<NSC>13b</NSC>
</table1>
<table1>
<ID>3</ID>
<AGD>11c</AGD>
<SNN>12c</SNN>
<NSC>13c</NSC>
</table1>
</Root>
Part B:
file2.xml
<Root>
<table2>
<ID>1</ID>
<NSC></NSC>
<AGD></AGD>
<SNN></SNN>
<THY></THY>
Part C:
file3.xml
<Root>
<table1>
<ID><I</ID>
<AGD>11</AGD>
<SNN>12</SNN>
<NSC></NSC>
<THY></THY>
</table1>
<table1>
<ID>2</ID>
<AGD></AGD>
<SNN>12b</SNN>
<NSC>13b</NSC>
<THY></THY>
</table1>
<table1>
<ID>3</ID>
<AGD>11c</AGD>
<SNN>12c</SNN>
<NSC>13c</NSC>
<THY></THY>
</table1>
</Root>
Thanks,
Victor
ASKER
Help!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank You.
do you have a sample file to show how the content looks like?