static void Main(string[] args) { XPathDocument doc = new XPathDocument(@"items.xml"); XPathNavigator nav = doc.CreateNavigator(); CustomContext ctx = new CustomContext(); XPathExpression expr = nav.Compile(@"*//item[contains(upper-case(string(@value)), 'AB')]"); expr.SetContext(ctx); XPathNodeIterator nodes = nav.Select(expr); foreach (XPathItem node in nodes) { Console.WriteLine(node.Value); } }
public static bool XQuery([SqlFacet(MaxSize = -1)]String value, String expression) { if (!String.IsNullOrEmpty(value)) { using (StringReader sr = new StringReader(value)) { XPathDocument doc = new XPathDocument(sr); XPathNavigator nav = doc.CreateNavigator(); CustomContext ctx = new CustomContext(); XPathExpression expr = nav.Compile(expression); expr.SetContext(ctx); XPathNodeIterator nodes = nav.Select(expr); return nodes.Count > 0; } } return false; }