开发者

Does there exist a .NET XPath 'diff' command for two XmlDocuments?

开发者 https://www.devze.com 2022-12-19 23:35 出处:网络
I have a catalog processor I\'ve built that updates itself by evaluating an xml based manifest file for the current state and comparing it to the local manifest.xml.

I have a catalog processor I've built that updates itself by evaluating an xml based manifest file for the current state and comparing it to the local manifest.xml.

I currently process every node to look for a difference in some of the attributes to determine if an update needs to occur. I loop through every node in the tree.

I was wondering if there was a more optimized XPath or similar way to do a 'diff' on the 2 XmlDocuments and have it return all of the nodes that are different so I can only process those.

This is a .NET 2.0 C# application.

Thanks,

开发者_如何学JAVA

John


I've used Xml Diff Patch in the past, have a look: http://msdn.microsoft.com/en-us/library/aa302294.aspx


There is no additional help you are going to get from XPath. To acheive this sort of thing I would get the editing application to assist. I've built systems where I've added an attribute to a node indicating whether it has been updated, added or is to be deleted. I then cascade up the tree ensuring the each ancestor is marked dirty (unless already marked as one of these other states).

To post changes the XML is processed with XSL selecting all nodes with any such state on. A dirty node will have its attributes copied but only children with a state will be selected. Utlimately you end up with some XML which only contains changed items and a state indicate what change is to be applied. If concurrency management is needed I prefer to use a version number attribute.

0

精彩评论

暂无评论...
验证码 换一张
取 消