XElement中的通配符搜索

问题描述:

我正在使用XElement来搜索用户通过openfiledialog选择的XML文档。XElement中的通配符搜索

下面是代码:

private void dothis() 
    { 
     string query; 

     XElement xml = XElement.Load(path); 
     XNamespace ns = xml.GetDefaultNamespace(); 
     IEnumerable<XElement> symptoms = 


     from item in xml.Descendants(ns + "section") 

     where (string) item.Element(ns + "text") == queryString.Text 
     select item; 

     // Execute the query 
     foreach (var complaints in symptoms) 
     { 
      // Instantiate the writer 
      _writer = new TextBoxStreamWriter(txtConsole); 
      // Redirect the out Console stream 
      Console.SetOut(_writer); 


      Console.WriteLine(complaints); 

     } 

     //Pause the application 
     Console.ReadLine(); 
    } 

我想打一个基于queryString.text是一个通配符查询。

所以文本字段中可能包含混乱,恶心,头痛

如果我只需键入混乱到我的queryString文本框,然后我希望它仍然位于该元素和节点。

谢谢

所以,它听起来就像你想要的是:

where item.Element(ns + text).Value.Contains(queryString.Text) 
请问

为你工作?

+0

是的,我想要的就是......我应该在4个小时前问过。谢谢!!! – user2212561 2013-03-26 17:34:11