【问题标题】:search xml using xpath - Treeview使用 xpath 搜索 xml - Treeview
【发布时间】:2013-08-16 09:50:26
【问题描述】:

我有一个绑定到 XmlDataSource 的树视图。我想在这个 XmlDataSource 的正文中搜索关键字并重新绑定树视图。找到描述它的 article,但我的搜索没有返回任何内容。

我的 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>

我使用的代码在按钮上单击如下,并输入“this”作为关键字:

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

【问题讨论】:

  • 因为“body”不包含“this”类型“This is body 1”

标签: c# asp.net xml xpath treeview


【解决方案1】:

试试这个:

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

【讨论】:

  • 感谢现在返回节点。我现在如何将树视图设置为具有完整路径。例如文章->文件夹->文章->搜索文章
  • 是的,但如果我这样做 tvCMSArts.SelectedNode.ValuePath;这将为空。
  • 为您的完整 aspx 代码提供 XMLDATASource、Treeview 和事件代码
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-02-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-28
相关资源
最近更新 更多