I\'m using .NET 2.0, and a recent code change has invalidated my previous Assert.AreEqual call (which compared two strings of XML). Only one element of the XML is actually
I ended up getting the result I wanted with the following code:
private static void ValidateResult(string validationXml, XPathNodeIterator iterator, params string[] excludedElements)
{
while (iterator.MoveNext())
{
if (!((IList)excludedElements).Contains(iterator.Current.Name))
{
Assert.IsTrue(validationXml.Contains(iterator.Current.Value), "{0} is not the right value for {1}.", iterator.Current.Value, iterator.Current.Name);
}
}
}
Before calling the method, I create a navigator on the instance of XmlDocument this way:
XPathNavigator nav = xdoc.CreateNavigator();
Next, I create an instance of XPathExpression, like so:
XPathExpression expression = XPathExpression.Compile("/blah/*");
I call the method after creating an iterator with the expression:
XPathNodeIterator iterator = nav.Select(expression);
I'm still figuring out how to optimize it further, but it does the trick for now.