private bool CompareFragment(XQueryContext context, string sourceFile, XQueryNodeIterator iter, XmlSpace space) { StringBuilder sb = new StringBuilder(); sb.AppendLine("<?xml version='1.0'?>"); sb.Append("<root>"); TextReader textReader = new StreamReader(sourceFile, true); sb.Append(textReader.ReadToEnd()); textReader.Close(); sb.Append("</root>"); XmlReaderSettings settings = context.GetSettings(); XmlReader reader = XmlReader.Create(new StringReader(sb.ToString()), settings); XQueryDocument doc1 = new XQueryDocument(reader, space); doc1.Fill(); context.AddDocument(doc1); XQueryDocument doc2 = context.CreateDocument(); XQueryDocumentBuilder builder = new XQueryDocumentBuilder(doc2); builder.WriteStartDocument(); builder.WriteStartElement("root", ""); Core.WriteNode(context.Engine, builder, iter.Clone()); builder.WriteEndElement(); XQueryNodeIterator iter1 = new NodeIterator(new XPathItem[] { doc1.CreateNavigator() }); XQueryNodeIterator iter2 = new NodeIterator(new XPathItem[] { doc2.CreateNavigator() }); TreeComparer comparer = new TreeComparer(); comparer.IgnoreWhitespace = true; bool res = comparer.DeepEqual(iter1, iter2); return res; }
private IEnumerable<XPathItem> DocumentIterator(XQueryContext context, XQueryNodeIterator iter) { foreach (XPathItem item in iter) { XPathNavigator nav = item as XPathNavigator; if (nav != null && nav.NodeType != XPathNodeType.Root) { XQueryDocument doc = context.CreateDocument(); XQueryDocumentBuilder builder = new XQueryDocumentBuilder(doc); builder.WriteStartDocument(); Core.WriteNode(context.Engine, builder, nav); yield return doc.CreateNavigator(); } else yield return item; } }