关于xml的模糊查询问题,请指点

monkeys 2004-06-07 11:13:23
XML文件:
<Persons>
<Person id="1">
<Name>李一</Name>
<Sex>男</Sex>
</Person>
<Person id="2">
<Name>李二</Name>
<Sex>女</Sex>
</Person>
<Person id="3">
<Name>李三</Name>
<Sex>男</Sex>
</Person>
<Person id="4">
<Name>陈四</Name>
<Sex>男</Sex>
</Person>
<Person id="5">
<Name>李四</Name>
<Sex>女</Sex>
</Person>
</Persons>

现在,我希望针对“姓名”做一个模糊查询,在用户输入:“李”的时候,将姓李的资料全部显示出来,请高手帮忙指点,最好有源代码,谢谢了!
...全文
157 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
孟子E章 2004-06-07
  • 打赏
  • 举报
回复
System.Xml.XmlDocument x = new System.Xml.XmlDocument();
x.Load(Server.MapPath("x1.xml"));
System.Xml.XmlNodeList nodes = x.SelectNodes("//Name");
foreach(System.Xml.XmlNode y in nodes)
{
if(y.InnerText.IndexOf("李") >-1)
Response.Write(y.InnerText);
}
monkeys 2004-06-07
  • 打赏
  • 举报
回复
自己顶
antshome 2004-06-07
  • 打赏
  • 举报
回复
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();

doc.Load("file:///d:/test.xml");

foreach (System.Xml.XmlNode n in doc.DocumentElement.SelectNodes("Person[contains(Name,'李')]"))
{
MessageBox.Show(n.InnerXml);
}
哈哈007哈 2004-06-07
  • 打赏
  • 举报
回复
ok
Ctoyun 2004-06-07
  • 打赏
  • 举报
回复
up

110,537

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧