我有一个包含2个客户节点(当前和更新)的XML文档。我希望能够遍历并生成生成的XML文档,以合并客户及其各种元素(地址,联系人,帐户等)以及归档和父级别的状态。解决方案需要能够遍历n个子元素,这些子元素本身可能有n个子元素。输入XML的格式可以更改。如果有帮助,我可以制作Ids属性。
输入:
<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>
输出:
<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>