Victor Charles
asked on
Help with copying data from file2 to file1 only when data element in File1 is empty using VB.NET
How do I copy data from File2 to File1 for matching condition (Receiver and AGD values are identical in both files) only when data elements in file1 are empty and save the results in File3? I'm trying to avoid copying over existing data in file1. Also is there a way to avoid hard coding the data elements? my actual project includes much more data elements, if at all possible, would be best if I can avoid hard coding them.
File1.xml
<?xml version="1.0" encoding="utf-8"?>
<Root>
<Table1>
<Link_ID>1</Link_ID>
<Receiver>USA</Receiver>
<AGD>XXX</AGD>
<NSC>FFF</NSC>
<FCT>UUU</FCT>
</Table1>
<Table1>
<Link_ID>2</Link_ID>
<Receiver>BEL</Receiver>
<AGD></AGD>
<NSC></NSC>
<FCT>HHH</FCT>
</Table1>
<Table1>
</Root>
File2.xml
<?xml version="1.0" encoding="utf-8"?>
<Root>
<Table2>
<Link_ID>1</Link_ID>
<Receiver>USA</Receiver>
<AGD>XXX</AGD>
<NSC>YYY</NSC>
<FCT>LLLL</FCT>
</Table2>
<Table2>
<Link_ID>2</Link_ID>
<Receiver>BEL</Receiver>
<AGD>XXX</AGD>
<NSC>OOO</NSC>
<FCT>XXX</FCT>
</Table2>
<Table2>
</Root>
File3.xml
<?xml version="1.0" encoding="utf-8"?>
<Root>
<Table1>
<Link_ID>1</Link_ID>
<Receiver>USA</Receiver>
<AGD>XXX</AGD>
<NSC>FFF</NSC>
<FCT>UUU</FCT>
</Table1>
<Table1>
<Link_ID>2</Link_ID>
<Receiver>BEL</Receiver>
<AGD>OOO</AGD>
<NSC>XXX</NSC>
<FCT>HHH</FCT>
</Table1>
<Table1>
</Root>
File1.xml
<?xml version="1.0" encoding="utf-8"?>
<Root>
<Table1>
<Link_ID>1</Link_ID>
<Receiver>USA</Receiver>
<AGD>XXX</AGD>
<NSC>FFF</NSC>
<FCT>UUU</FCT>
</Table1>
<Table1>
<Link_ID>2</Link_ID>
<Receiver>BEL</Receiver>
<AGD></AGD>
<NSC></NSC>
<FCT>HHH</FCT>
</Table1>
<Table1>
</Root>
File2.xml
<?xml version="1.0" encoding="utf-8"?>
<Root>
<Table2>
<Link_ID>1</Link_ID>
<Receiver>USA</Receiver>
<AGD>XXX</AGD>
<NSC>YYY</NSC>
<FCT>LLLL</FCT>
</Table2>
<Table2>
<Link_ID>2</Link_ID>
<Receiver>BEL</Receiver>
<AGD>XXX</AGD>
<NSC>OOO</NSC>
<FCT>XXX</FCT>
</Table2>
<Table2>
</Root>
File3.xml
<?xml version="1.0" encoding="utf-8"?>
<Root>
<Table1>
<Link_ID>1</Link_ID>
<Receiver>USA</Receiver>
<AGD>XXX</AGD>
<NSC>FFF</NSC>
<FCT>UUU</FCT>
</Table1>
<Table1>
<Link_ID>2</Link_ID>
<Receiver>BEL</Receiver>
<AGD>OOO</AGD>
<NSC>XXX</NSC>
<FCT>HHH</FCT>
</Table1>
<Table1>
</Root>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Below is the code I'm using but would like to avoid hard coding the names of the data elements. How do I modify the code to avoid that? If easier, I can also include the name of all the fields in a string variable (i.e. s = NSC, AGD, RECEIVER,....)
Open in new window