In the end, I got the result I need, with the following code:
private static void ValidateResult(string validationXml, XPathNodeIterator iterator, params string[] excludedElements) { while (iterator.MoveNext()) { if (!((IList<string>)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 in the XmlDocument instance as follows:
XPathNavigator nav = xdoc.CreateNavigator();
Next, I create an instance of XPathExpression, for example:
XPathExpression expression = XPathExpression.Compile("/blah/*");
I call the method after creating an iterator with an expression:
XPathNodeIterator iterator = nav.Select(expression);
I am still figuring out how to optimize it further, but now this is a trick.
Scott Lawrence Nov 19 '08 at 23:08 2008-11-19 23:08
source share