Xpath请教

computerre 2010-11-16 03:18:51
程序中有一段
string Xpath = "//Task/[@Source='C:\\测试' and Dest='D:\\我的文档']";
XmlNode MyXmlNode = MyXmlDocument.SelectSingleNode(Xpath);
string TempSuffix = MyXmlNode.Attributes["Suffix"].Value.ToString();

执行后总是报错"表达式的计算结果必须为节点集。"
不知什么原因,请高手赐教
...全文
80 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Siupan 2010-11-18
  • 打赏
  • 举报
回复
楼上正解
//Task[@Source='C:\\测试' and @Dest='D:\\我的文档']
对于属性前要加@符号
whycom 2010-11-16
  • 打赏
  • 举报
回复
上面有些错
//Task[@Source='C:\\测试' and @Dest='D:\\我的文档']
whycom 2010-11-16
  • 打赏
  • 举报
回复
"//Task/[@Source='C:\\测试' and Dest='D:\\我的文档']"
改为
"//Task[@Source='C:\\测试' and Dest='D:\\我的文档']";
试试
computerre 2010-11-16
  • 打赏
  • 举报
回复
我的xml 文档是:
<?xml version="1.0" standalone="yes" ?>
<config>
<FileCopy>
<Task TaskId="2" Name="任务2" Source="C:\测试" Dest="D:\我的文档" Suffix="txt" Frequency="每小时1点" />
</FileCopy>
</config>
whycom 2010-11-16
  • 打赏
  • 举报
回复
你的xml文档?

string Xpath = "//Task/[@Source='C:\\测试' and Dest='D:\\我的文档']";这句应该有问题
改为string Xpath = "//Task/包含source和dest的节点名[@Source='C:\\测试' and Dest='D:\\我的文档']";

111,129

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧