XElement中的通配符搜索
本文关键字:搜索 通配符 XElement | 更新日期: 2023-09-27 18:06:03
我使用XElement来搜索用户通过openfiledialog选择的XML文档。
代码如下:
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的查询。文本为通配符。
所以文本字段可能包含混淆,恶心,头痛
如果我只是在queryString文本框中输入混淆,那么我希望它仍然定位该元素和节点。
谢谢
听起来你想要的只是:
where item.Element(ns + text).Value.Contains(queryString.Text)
这样行吗?