0

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

2
  • 2
    You should probably show your XML Commented Jul 12, 2013 at 8:08
  • Always post example XML, you will receive better answers when doing so. Also read about the SSCCE. Your current query is saying "If there are at least two subclaims in all input, return those, otherwise return all claims". Is this what you want to achieve? As far as I can derive your XML structure from your expression, I'm not too sure about that. And: You should accept answers if they solved your question, read How to Ask. Commented Jul 12, 2013 at 16:16

2 Answers 2

1

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']
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.