Reputation: 177
I have the following code to execute xpath expression:
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:
if(count(//Claims[ClaimNoticeCd='SUBCLAIM']) > 1) then //Claims[ClaimNoticeCd='SUBCLAIM'] else //Claims[ClaimNoticeCd='CLAIM']" has invalid token
Upvotes: 0
Views: 179
Reputation: 38662
In XPath 1.0 there is no if/then/else, but you can fake it using opposing predicates and node set union:
//Claims[count(//Claims[ClaimNoticeCd='SUBCLAIM'])>1][ClaimNoticeCd='SUBCLAIM']
|
//Claims[count(//Claims[ClaimNoticeCd='SUBCLAIM'])<=1][ClaimNoticeCd='CLAIM']
Upvotes: 1
Reputation: 1925
The statement you're using is 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.
http://msdn.microsoft.com/en-us/library/ms256471.aspx
Upvotes: 0