Reputation: 423
I got the example from MSDN about how to compare two XML with XML Diff and Patch. MSDN XML Diff & Path
It is an easy example but I dont get what I expect.
I have the following XMls:
<a>
<component>A</component>
<component>4</component>
</a>
and
<a>
<component>A</component>
<component>5</component>
</a>
Running the tool code I dont get exaclty the difference. The output which I get is:
<a>
<component>A</component>
<component>5</component>
</a>
But for my purposes I would like to get just the difference which differs from the original, in this case.
<a>
<component>4</component>
</a>
Does anyone know how I can adapt the code to my solution.
Thank you very much.
edit code used:
(Here I find out the differences between the files)
public void GenerateDiffGram(string originalFile, string finalFile,
XmlWriter diffGramWriter)
{
XmlDiff xmldiff = new XmlDiff(XmlDiffOptions.IgnoreChildOrder |
XmlDiffOptions.IgnoreNamespaces |
XmlDiffOptions.IgnorePrefixes);
bool bIdentical = xmldiff.Compare(originalFile, newFile, false, diffgramWriter);
diffgramWriter.Close();
}
Patching up the original file to create the new changed file.
public void PatchUp(string originalFile, String diffGramFile, String OutputFile)
{
XmlDocument sourceDoc = new XmlDocument(new NameTable());
sourceDoc.Load(originalFile);
XmlTextReader diffgramReader = new XmlTextReader(diffGramFile);
xmlpatch.Patch(sourceDoc,diffgramReader);
XmlTextWriter output = new XmlTextWriter(OutputFile,Encoding.Unicode);
sourceDoc.Save(output);
output.Close();
}
Upvotes: 2
Views: 5295