日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

关于xml的模糊查询问题

發布時間:2025/6/17 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 关于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的模糊查询问题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。