关于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的模糊查询问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: FLV播放器 源码二例
- 下一篇: IE不能為讀(written)問題解決(