lundi 6 avril 2015

Conditional expressions in C# using XPath

I've to create an entity object using the data available from an input xml. The value of one of the properties of this object depends on a condition and it looks like this in XPath :



if (//trade/tradeHeader/tradeTypology/tradeCategoryTypology[tradeCategory = 'TechnicalCancellation']) then 'Y' else 'N'")


And the below function takes this XPath and the xml document :



private static string GetValueFromXml(XmlDocument xDoc, string xPath)
{
var nod = xDoc.SelectSingleNode(xPath);
if (nod != null)
return nod.InnerText;
return null;
}


However, it doesn't work. The error is :


'if (//trade/tradeHeader/tradeTypology/tradeCategoryTypology[tradeCategory = 'TechnicalCancellation']) then 'Y' else 'N'' has an invalid token.


So my questions are :



  1. Is this conditional expression supported in C#/.Net (4.5) ?

  2. If not, what's the recommended approach when we have to check for multiple conditions in XPath ?


Thanks Dileep


Aucun commentaire:

Enregistrer un commentaire