I want to copy (element/attribute)values from one XML file to another but at the moment I cannot figure out how to go about it. I have values in file A which I want to copy to file B. File B has same elements/attributes more or less with the only difference of being empty. I am taking this approach since I don't have the schema for neither file.
Following are the contents of file A:
<status>1</status>
<arguments>
<argument name="ZONE">
<value>ZONE 1</value>
</argument>
<argument name="JOB_DATES">
<argument name="JOB_DATE">
<value>2014-01-20</value>
</argument>
</argument>
<argument name="PERSON">
<argument name="NAME_1">
<value>JOHN</value>
</argument>
<argument name="NAME_2">
<value>SMITH</value>
</argument>
</argument>
<argument name="FIRST_SCHEDULE_JOB">
<value>true</value>
</argument>
<argument name="EMPLOYEE">
<value>ABXX011</value>
</argument>
</arguments>
<place placeType="JOB_SITE">
<site>
<street>DUKE 2</street>
<house_name>TECH HOUSE</house_name>
<zip>QZ12324</zip>
<city>NYC</city>
<province>NY</province>
<country>USA</country>
</site>
<contact>
<Name>JOHN</Name>
<Name_1>SMITH</Name_1>
<address>
<street>DUKE 2</street>
<house_name>TECH HOUSE</house_name>
<zip>QZ12324</zip>
<city>NYC</city>
<province>NY</province>
<country>USA</country>
</address>
</contact>
Following are the contents of file B:
<status></status>
<arguments>
<argument name="ZONE">
<value></value>
</argument>
<argument name="JOB_DATES">
<argument name="JOB_DATE">
<value></value>
</argument>
</argument>
<argument name="PERSON">
<argument name="NAME_1">
<value></value>
</argument>
<argument name="NAME_2">
<value></value>
</argument>
</argument>
<argument name="FIRST_SCHEDULE_JOB">
<value></value>
</argument>
<argument name="EMPLOYEE">
<value></value>
</argument>
</arguments>
<place placeType="JOB_SITE">
<contact>
<Name></Name>
<Name_1></Name_1>
<address>
<street></street>
<house_name></house_name>
<zip></zip>
<city></city>
<province></province>
<country></country>
</address>
</contact>
<site>
<street></street>
<house_name></house_name>
<zip></zip>
<city></city>
<province></province>
<country></country>
</site>
</place>
I want to loop through the elements in file B and fill the value from file A ie: The ZONE element (attribute ZONE) is filled with the ZONE 1 value.
I have tried with the XMLTextReader but hadn't had any luck so far:
while (emptyFile.Read())
{
switch (emptyFile.NodeType)
{
case XmlNodeType.Element: // The node is an element.
emptyFile.Name = sourceFile.Name;
........
}
}
Some help is greatly appreciated
Thanks