xpath上的Xmlnodelist错误包含双引号 [英] Xmlnodelist error on xpath contains double quote

查看:87
本文介绍了xpath上的Xmlnodelist错误包含双引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我的xmlnodelist包含以下字符串

Hi,

my xmlnodelist contains below string

<rows><row rowID=\"1\"><ValueColumn>value1\"</ValueColumn></row></rows>





string a =



string a=

"rows/row[ValueColumn=\"value1\"\"]"







XmlNodeList optionNodes = _optionNode.SelectNodes(a);



收到错误,令牌无效。



我尝试过:




getting error ,invalid token.

What I have tried:

"/*/rows/row[ValueColumn=\"value4witha\"\"]"



无效


not worked

推荐答案

使用单曲引用您正在寻找的价值:

Use single quotes around the value you're looking for:
"/*/rows/row[ValueColumn='value1\"']"



注意:如果你需要搜索包含单引号和双引号混合的值,事情会变得复杂得多。你基本上必须拆分字符串,以便每个部分只包含一种类型的引用,使用另一种类型的引用来开始和结束该字符串,并使用 concat 来组合他们。例如:


NB: If you need to search for values which contain a mixture of single and double quotes, things become much more complicated. You basically have to split the strings up so that each part only contains one type of quote, use the other type of quote to start and end that string, and use concat to combine them. For example:

<row><ValueColumn>I'd like it if "This" was easier!</ValueColumn></row>

"row[ValueColumn=concat(\"I'd like it if \", '\"This\" was easier!')]"



XPath 2.0显然让你通过将它们加倍来逃避引用来简化:


XPath 2.0 apparently makes this easier by letting you escape quotes by doubling them up:

"row[ValueColumn=\"I'd like it if \"\"This\"\" was easier!\"]"
"row[ValueColumn='I''d like it if \"This\" was easier!']"

不幸的是,。 NET从未实现过XPath 2.0,所以你不能在C#中工作。



c# - 在Xpath中使用引号 - 堆栈溢出 [ ^ ]

Unfortunately, .NET has never implemented XPath 2.0, so you this won't work in C#.

c# - Using quotes in Xpath - Stack Overflow[^]


这篇关于xpath上的Xmlnodelist错误包含双引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆