0

我有以下代码来执行 xpath 表达式:

nodeList = xmlDocument.SelectNodes("if(count(//Claims[ClaimNoticeCd='SUBCLAIM']) > 1)
then //Claims[ClaimNoticeCd='SUBCLAIM']   else //Claims[ClaimNoticeCd='CLAIM']");

但这给了我 xpath 异常,例如:

if(count(//Claims[ClaimNoticeCd='SUBCLAIM']) > 1) then //Claims[ClaimNoticeCd='SUBCLAIM'] else //Claims[ClaimNoticeCd='CLAIM']" 具有无效令牌

4

2 回答 2

1

在 XPath 1.0 中没有 if/then/else,但您可以使用相反的谓词和节点集联合来伪造它:

//Claims[count(//Claims[ClaimNoticeCd='SUBCLAIM'])>1][ClaimNoticeCd='SUBCLAIM']
  |
//Claims[count(//Claims[ClaimNoticeCd='SUBCLAIM'])<=1][ClaimNoticeCd='CLAIM']
于 2013-07-12T16:13:33.227 回答
0

您使用的语句是 XPath 2.0。.NET 框架不支持 XPath 2.0,如果需要,您将不得不依赖 3rd 方库。

http://msdn.microsoft.com/en-us/library/ms256471.aspx

于 2013-07-12T10:34:28.997 回答