2013-08-16 53 views
0

我有一個綁定到XmlDataSource的treeview。我想在這個XmlDataSource的主體上搜索關鍵字並重新綁定樹視圖。發現這個描述它的這個article,但我的搜索沒有返回任何東西。使用xpath搜索xml - Treeview

我的XML看起來象下面這樣:

<?xml version="1.0" encoding="utf-8"?> 
<articles name="articles"> 
    <folder name="Folder1"> 
    <article name="art1"> 
     <body>This is body 1</body> 
     <createuser>someuser</createuser> 
     <createddate>28/02/2013 06:24:34</createddate> 
    </article> 
    <article name="art2"> 
     <body>&lt;p&gt; this is body 2</body> 
     <createuser>someuser2</createuser> 
     <createddate>28/02/2013 06:30:36</createddate> 
    </article> 
    </folder> 
</articles> 

,我已經使用的代碼是按鍵點擊下面和我打字「本」爲關鍵字:

protected void btnSearch_Click(object sender, EventArgs e) 
{ 
    XmlArticle.XPath = "/articles/folder/article[body='" + txbSearch.Text + "']"; 
    //XmlArticle.XPath = "/articles/folder[article/body='" + txbSearch.Text + "']"; //tried this too 
    tvCMSArts.DataBind(); 
} 
+0

Becouse「body」不包含「this」類型「This is body 1」 –

+0

檢查我的答案.. –

回答

1

試試這個:

XmlArticle.XPath = "/articles/folder/article[contains(body,'" + txbSearch.Text + "')]"; 
+0

謝謝這現在返回節點。我該如何設置樹狀圖以使其具有完整路徑。例如文章 - >文件夾 - >文章 - >搜索文章 – Zaki

+0

它已經給你過濾的數據 –

+0

是的,但如果我做tvCMSArts.SelectedNode.ValuePath;這將是空的。 – Zaki