开发者

Facing Problem with Xpath if then else concept

XML:

<additionalFields>
    <field name="dataKey">3868</field>
    <field name="distribution">140</field>
</additionalFields>

I would like to execute following If else Xpath statement.

String text = nav.Evaluate("if(/additionalFields/field[@name='distribution']/text() = '140') then 'C' else ' ' ").ToString();

However I am getting following error message:

'if(/additionalFields/field[@name='distribution']/text() = '140') then 'C' else ' ' ' has an invalid token.

Is there any other way to achieve the res开发者_开发百科ult? Any help would be appreciated.


I guess you are using the .NET Framework. It does not implement all XPath 2.0 features yet. In your specific example there is not problem since you can do the logic in your code.

If this won't fit your need, you can use either XSLT for that (although it is much too complex for simpler needs).

Another way would be to use third party libraries which support XPath 2.0 or XQuery, for example SAXON or XQSharp.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜