Raj
Raj

Reputation: 177

Error in executing xpath expression in c#

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

Answers (2)

Jens Erat
Jens Erat

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

Plymouth223
Plymouth223

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

Related Questions