I know that there are already several questions about this topic, but none of the solutions seem to work for me. I already tried everything with Diff in the name, XMLUnit, FatAntelope, xdocument and several more. My main problem with These approaches was, that I either don't get the output I want or no output at all. The best approach was XmlDiffLib with the following code:
var exampleA = File.ReadAllText(@"Error0.xml");
var exampleB = File.ReadAllText(@"Error1.xml");
var diff = new XmlDiff(exampleA, exampleB);
diff.CompareDocuments(new XmlDiffOptions());
Console.WriteLine(diff.ToString());
Console.ReadLine();
but it only shows me changed text (fe <error>TextThatCanBeDetected</error>
). I want additional to check for changed attributes ( <error same="IWantToCheckThisToo"/>
)
Inline Edit diff has other flaws too, for example if in the new XML is an extra tag it won't be recognized as one End inline edit
I would be very happy to help me with this problem, below is an example of the XML file
<?xml version="1.0" encoding="UTF-8"?>
<message>
<header>
</header>
<body>
<error name="MyName"> MyInnerXML </error>
</body>
</message>
(Note that the original file is around 100 lines long)
EDIT
So one answer was to change the CompareDocuments method to
diff.CompareDocuments(new XmlDiffOptions { IgnoreAttributes=false });
(I used wudri and hudri for the name tag, it tells me that wudri is not found but nothing about hudri)
Simply specify to not ignore attributes in your XmlDiffOptions:
diff.CompareDocuments(new XmlDiffOptions { IgnoreAttributes = false });
Moreover you need to specify to compare both directions to identify both values for the differing node:
diff.CompareDocuments(new XmlDiffOptions { IgnoreAttributes = false, TwoWayMatch = true });
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.