in src/Application/FormMain.cs [2624:2729]
private void DoCompare(string changed)
{
CleanupTempFiles();
// todo: add UI for setting XmlDiffOptions.
XmlDiffOptions options = XmlDiffOptions.None;
if ((bool)this._settings["XmlDiffIgnoreChildOrder"])
{
options |= XmlDiffOptions.IgnoreChildOrder;
}
if ((bool)this._settings["XmlDiffIgnoreComments"])
{
options |= XmlDiffOptions.IgnoreComments;
}
if ((bool)this._settings["XmlDiffIgnorePI"])
{
options |= XmlDiffOptions.IgnorePI;
}
if ((bool)this._settings["XmlDiffIgnoreWhitespace"])
{
options |= XmlDiffOptions.IgnoreWhitespace;
}
if ((bool)this._settings["XmlDiffIgnoreNamespaces"])
{
options |= XmlDiffOptions.IgnoreNamespaces;
}
if ((bool)this._settings["XmlDiffIgnorePrefixes"])
{
options |= XmlDiffOptions.IgnorePrefixes;
}
if ((bool)this._settings["XmlDiffIgnoreXmlDecl"])
{
options |= XmlDiffOptions.IgnoreXmlDecl;
}
if ((bool)this._settings["XmlDiffIgnoreDtd"])
{
options |= XmlDiffOptions.IgnoreDtd;
}
this.xmlTreeView1.Commit();
this.SaveIfDirty(false);
string filename = this._model.FileName;
// load file from disk, as saved doc can be slightly different
// (e.g. it might now have an XML declaration). This ensures we
// are diffing the exact same doc as we see loaded below on the
// diffView.Load call.
XmlDocument original = new XmlDocument();
XmlReaderSettings settings = _model.GetReaderSettings();
using (XmlReader reader = XmlReader.Create(filename, settings))
{
original.Load(reader);
}
XmlDocument doc = new XmlDocument();
settings = _model.GetReaderSettings();
using (XmlReader reader = XmlReader.Create(changed, settings))
{
doc.Load(reader);
}
//output diff file.
string diffFile = Path.Combine(Path.GetTempPath(),
Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".xml");
this._tempFiles.AddFile(diffFile, false);
bool isEqual = false;
XmlTextWriter diffWriter = new XmlTextWriter(diffFile, Encoding.UTF8);
diffWriter.Formatting = Formatting.Indented;
using (diffWriter)
{
XmlDiff diff = new XmlDiff(options);
isEqual = diff.Compare(original, doc, diffWriter);
}
if (isEqual)
{
//This means the files were identical for given options.
MessageBox.Show(this, SR.FilesAreIdenticalPrompt, SR.FilesAreIdenticalCaption,
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
string tempFile = Path.Combine(Path.GetTempPath(),
Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".htm");
_tempFiles.AddFile(tempFile, false);
using (XmlReader diffGram = XmlReader.Create(diffFile, settings))
{
XmlDiffView diffView = new XmlDiffView();
using (var reader = new XmlTextReader(filename))
{
diffView.Load(reader, diffGram);
using (TextWriter htmlWriter = new StreamWriter(tempFile, false, Encoding.UTF8))
{
SideBySideXmlNotepadHeader(this._model.FileName, changed, htmlWriter);
diffView.GetHtml(htmlWriter);
htmlWriter.WriteLine("</body></html>");
}
}
}
WebBrowser.OpenUrl(this.Handle, tempFile);
}