首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >引发异常: System.Xml.dll中的“System.Xml.XPath.XPathException”

引发异常: System.Xml.dll中的“System.Xml.XPath.XPathException”
EN

Stack Overflow用户
提问于 2018-07-30 01:16:51
回答 1查看 265关注 0票数 0

每当我试图保存我的帖子时,我都会得到这样的错误

引发

异常: System.Xml.dll中的“System.Xml.XPath.XPathException”

供您参考:我从一个XSLT文件发送一个响应查询字符串,

 <td><a class="btn btn-default" href="EditPost.aspx?pid={@pid}">Edit</a> <a class="btn btn-danger" href="#">Delete</a></td>

接下来,web表单将捕获查询字符串,并从我的xml数据中读取选定的帖子。

 protected void Update_btn_click(object sender, EventArgs e)
    {
        string new_title = newtitle.Text.ToString();
        string new_description = update_des.Value.ToString();
        string postid = Request.QueryString["pid"];
        string docPath = @"~/Data/blog_post.xml";
         XmlDocument xml_doc = new XmlDocument();

        xml_doc.Load(Server.MapPath(docPath));

        XmlNode elemList = xml_doc.SelectSingleNode("/Posts/post[@pid=" + postid + "]/title");
        System.Diagnostics.Debug.WriteLine(elemList);
    }

我的XML数据:

<Posts>
    <post pid="pid2623">
    <title>Test</title>
    <description>Test</description>
    <subtitle>Test</subtitle>
    <date>7/29/2018 12:00:00 AM</date>
    <author>est</author>
  </post>
</Posts>
EN

回答 1

Stack Overflow用户

发布于 2018-07-30 02:53:47

在XPath中,您可以将像pid2623这样的值视为字符串,但为此,您需要用引号将其括起来,例如xml_doc.SelectSingleNode("/Posts/post[@pid='" + postid + "']/title")xml_doc.SelectSingleNode(string.Format("/Posts/post[@pid='{0}']/title", postid))

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51582721

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档