简体   繁体   English

在C#中执行XPath表达式时出错

[英]Error in executing xpath expression in c#

I have the following code to execute xpath expression: 我有以下代码来执行xpath表达式:

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

But it is giving me xpath exception like: 但这给了我xpath异常,如:

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

In XPath 1.0 there is no if/then/else, but you can fake it using opposing predicates and node set union: 在XPath 1.0中没有if / then / else,但是您可以使用相反的谓词和节点集并集来伪造它:

//Claims[count(//Claims[ClaimNoticeCd='SUBCLAIM'])>1][ClaimNoticeCd='SUBCLAIM']
  |
//Claims[count(//Claims[ClaimNoticeCd='SUBCLAIM'])<=1][ClaimNoticeCd='CLAIM']

The statement you're using is XPath 2.0. 您使用的语句是XPath 2.0。 The .NET framework doesn't support XPath 2.0 and you'll have to rely on 3rd party libraries if you require it. .NET框架不支持XPath 2.0,如果需要,您将不得不依赖第三方库。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM