Zaki
Zaki

Reputation: 5600

search xml using xpath - Treeview

I have a treeview which is bound to XmlDataSource. I want to search on this XmlDataSource's body for a keyword and rebind the treeview. Found this article that describes it, but my search does not return anything.

My xml looks like below:

<?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>

and the code I have used is on Button click as below and am typing "this" as keyword:

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();
}

Upvotes: 0

Views: 396

Answers (1)

sangram parmar
sangram parmar

Reputation: 8736

Try this:

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

Upvotes: 1

Related Questions