I am trying to use xmldiffpatch when comparing two Xmls(one from a stream, the other from a file) and writing the diff patch to a stream.
The first method is to write my xml to a memory stream.
The second method loads an xml from a file and creates a stream for the patched file to be written into. The third method actually compares the two files and writes the third. The xmldiff.Compare(originalFile, finalFile, dgw); method takes (XmlReader, XmlReader, XmlWriter). I'm always getting that both files are identical, even though they are not, so I know that I am missing something.
Any help is appreciated!
public MemoryStream FirstXml()
{
string[] names = { "John", "Mohammed", "Marc", "Tamara", "joy" };
MemoryStream ms = new MemoryStream();
XmlTextWriter xtw= new XmlTextWriter(ms, Encoding.UTF8);
xtw.WriteStartDocument();
xtw.WriteStartElement("root");
foreach (string s in names)
{
xtw.WriteStartElement(s);
xtw.WriteEndElement();
}
xtw.WriteEndElement();
xtw.WriteEndDocument();
return ms;
}
public Stream SecondXml()
{
XmlReader finalFile =XmlReader.Create(@"c:\......\something.xml");
MemoryStream ms = FirstXml();
XmlReader originalFile = XmlReader.Create(ms);
MemoryStream ms2 = new MemoryStream();
XmlTextWriter dgw = new XmlTextWriter(ms2, Encoding.UTF8);
GenerateDiffGram(originalFile, finalFile, dgw);
return ms2;
}
public void GenerateDiffGram(XmlReader originalFile, XmlReader finalFile,
XmlWriter dgw)
{
XmlDiff xmldiff = new XmlDiff();
bool bIdentical = xmldiff.Compare(originalFile, finalFile, dgw);
dgw.Close();
StreamReader sr = new StreamReader(SecondXml());
string xmlOutput = sr.ReadToEnd();
if(xmlOutput.Contains("</xd:xmldiff>"))
{Console.WriteLine("Xml files are not identical");
Console.Read();}
else
{Console.WriteLine("Xml files are identical");Console.Read();}
}