C# xpath 查询问题

pengchengwanli pengchengwanli 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我要查询 :
条件:title='Harry Potter' 一定要注意,title值有单引号如何处理
目标:book的属性@category值是多少


<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
<book category="COOKING">
<title lang="en">'Everyday Italian'</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>

<book category="CHILDREN">
<title lang="en">'Harry Potter'</title>
<title lang="en">Everyday Italian</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>



已经有的方法

using System.Xml;
using System.Xml.XPath;

public string GetData(string strsql)
{
XPathNavigator nav;
XPathDocument docNav;
XPathNodeIterator NodeIter;

string strRetrun = string.Empty;
nav = docNav.CreateNavigator();
strExpression = "";//在这儿写查询语句
MessageBox.Show(strExpression);
NodeIter = nav.Select(strExpression);
while (NodeIter.MoveNext())
{
strRetrun += NodeIter.Current.Value;
};
return strRetrun;
}


或者给更好的建议
...全文
评论 4
收藏 已收藏
分享
返回顶部
pengchengwanli
C# 111,128 成员 642,536 内容