public Definitions(string definitionFile) { using (XmlReader reader = XmlReader.Create(definitionFile)) { XPathNavigator navigator = new XPathDocument(reader).CreateNavigator(); bool caseSensitive = XmlConvert.ToBoolean(navigator.SelectSingleNode("/NxDSL-Defs").GetAttribute("caseSensitive", "")); XPathNodeIterator atomPatterns = navigator.SelectDescendants("AtomPattern", "", false); while (atomPatterns.MoveNext()) { XPathNavigator atomPattern = atomPatterns.Current; RegexOptions options = RegexOptions.Compiled; if (!caseSensitive) { options |= RegexOptions.IgnoreCase; } Regex regex = new Regex("^\\s*" + atomPattern.GetAttribute("regex", "") + "$", options); definitions.Add(regex, atomPattern.InnerXml); } } }
/// <summary /> public static void SelectDescendentsSpeed(object it) { int iterations = (int)it; long start; long end; XPathNavigator context = new XPathDocument(@"..\data.xml").CreateNavigator(); XPathExpression expr = context.Compile("descendant-or-self::publishers"); context.MoveToFirstChild(); start = DateTime.Now.Ticks; for (int i = 0; i < iterations; i++) { context.Select(expr); } end = DateTime.Now.Ticks; //Console.WriteLine("Elapsed time for compiled expression select: {0}", TimeSpan.FromTicks(end - start).TotalMilliseconds); string ns = Schema.Namespace; start = DateTime.Now.Ticks; for (int i = 0; i < iterations; i++) { context.SelectDescendants("publisher", ns, true); } end = DateTime.Now.Ticks; //Console.WriteLine("Elapsed time for descendents select: {0}", TimeSpan.FromTicks(end - start).TotalMilliseconds); }