In my C# Program, I am loading a System.Xml.Linq.Xelement
variable with a portion of an XML file I'm trying to parse and feeding it various XPaths to evaluate values for using the XPathEvaluate()
method.
My challenge is that my XML has some numbers stored as exponential numbers and the XPath is ignoring them even though I'm reading that XPath 2.0 should allow for these being understood to be numbers.
A sample would look as follows:
XML (childNode
):
<Parent>
<Vals id="Val1">
<abc>1.8</abc>
</Vals>
<Vals id="Val2">
<abc>4.8552829108959736E-5</abc>
<def>4.940657864520423E-4</def>
<ghi>0.1262403356384331</ghi>
<jkl>0.0</jkl>
</Vals>
</Parent>
XPath (myXPath
):
sum(Parent/Vals[@id="Val2"]/*[self::abc | self::def | self::ghi | self::jkl][number(.)=number(.)])
and my code looks like:
var value= childNode.XPathEvaluate(myXPath);
I would expect the value to be:
value = 4.8552829108959736E-5 + 4.940657864520423E-4 + 0.126240335638433 + 0
= 0.126782954253994
But, rather I get:
value = 0.126240335638433 + 0
= 0.126240335638433
Any thoughts about any way this can be fixed in my C# code?