I have an XML document with 2 Customer Nodes (Current and Updated). I would like to be able to traverse through and produce a resulting XML document to merge the Customer and its various elements (Addresses, Contacts, Accounts, etc.) along with a status at the filed and parent level(s). The solution needs to be able to traverse through n number of child elements which may have n number of children themselves. The format of the input XML is open to change. I can make the Ids attributes if it helps.
Input:
<Customer Id="Current">
<CustId>1</CustId>
<CustName>Acme</CustName>
<Addresses>
<Address>
<AddressId>1</AddressId>
<Street>111 Main</Street>
</Address>
<Address>
<AddressId>2</AddressId>
<Street>222 Main</Street>
</Address>
<Contacts>
<Contact>
<ContactId>1</ContactId>
<ContactName>Tom</ContactName>
<ContactPhone>555-1212</ContactPhone>
</Contact>
</Contacts>
</Customer>
<Customer Id="Updated">
<CustId>1</CustId>
<CustName>Acme</CustName>
<Addresses>
<Address>
<AddressId>1</AddressId>
<Street>111 Main</Street>
</Address>
<Address>
<AddressId>3</AddressId>
<Street>333 Main</Street>
</Address>
<Contacts>
<Contact>
<ContactId>1</ContactId>
<ContactName>Tom</ContactName>
<ContactPhone>555-1212</ContactPhone>
</Contact>
</Contacts>
</Customer>
Output:
<Customer Id="Updated" status="Changed">
<CustId>1</CustId>
<CustName>Acme</CustName>
<CustRegion status="New"/>
<Addresses status="Changed">
<Address>
<AddressId>1</AddressId>
<Street>111 Main</Street>
</Address>
<Address Status="Deleted">
<AddressId>2</AddressId>
<Street>222 Main</Street>
</Address>
<Address Status="New">
<AddressId status="New">3</AddressId>
<Street status="New">222 Main</Street>
</Address>
<Contacts status="Changed">
<Contact status="Changed">
<ContactId>1</ContactId>
<ContactName>Tom</ContactName>
<ContactPhone tatus="New">555-1212</ContactPhone>
</Contact status="New">
</Contacts>
</Customer>