欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

关于xml的模糊查询问题

发布时间:2025/6/17 编程问答 43 豆豆
生活随笔 收集整理的这篇文章主要介绍了 关于xml的模糊查询问题 小编觉得挺不错的,现在分享给大家,帮大家做个参考.
关于xml的模糊查询问题

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>

现在,我希望针对“姓名”做一个模糊查询,在用户输入:“李”的时候,将姓李的资料全部显示出来,请高手帮忙指点,最好有源代码,谢谢了!

解决方法一: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);
}
解决方法2: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);
}



Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=131759

posted on 2006-12-16 21:51 suny2006 阅读(...) 评论(...) 编辑 收藏

转载于:https://www.cnblogs.com/suny2006/archive/2006/12/16/594434.html

总结

以上是生活随笔为你收集整理的关于xml的模糊查询问题的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。