XmlTextReader r1 = new XmlTextReader(Server.MapPath(<< doc 1 path >>));
XmlTextReader r2 = new XmlTextReader(Server.MapPath(<< doc 2 path >>));
bool files_equal = false;
bool done = false;
while (!done)
{
if (r1.Read() && r2.Read())
{
// Check that nodes are of the same depth, nodetype, name, valuetype and value.
// All things being equal, the nodes should always be of the same depth since
// we are sequentially looping through every node in each file at the same time.
// However, it doesn't hurt to verify...
// There are other properties you could check. This assumes that you don't care
// about any attributes on any node.
files_equal = (r1.Depth.Equals(r2.Depth)
&& r1.NodeType.Equals(r2.NodeType)
&& r1.Name.Equals(r2.Name)
&& r1.ValueType.Equals(r2.ValueType)
&& r1.Value.Equals(r2.Value));
if (!files_equal)
{
// No need to keep checking if we find even one inequality.
done = true;
}
}
else
{
// If we reach the end of either file, then we are done.
done = true;
}
}
r1.Close(); r1 = null;
r2.Close(); r2 = null;
Response.Write ("Files are " + files_equal ? "equal" : "not equal.");
Brandon
|