I am trying to parse some currency data in xml format. Below code does not work, but when I parse it all as string, it does work.
CurrencyName = (string)d.Element("CurrencyName"),
ForexBuying = ((decimal?)d.Element("ForexBuying")),
ForexSelling = ((decimal?)d.Element("ForexSelling")),
BanknoteBuying = ((decimal?)d.Element("BanknoteBuying")),
BanknoteSelling = ((decimal?)d.Element("BanknoteSelling")),
CrossRateEuro = ((decimal?)d.Element("CrossRateEuro")),
CrossRateUSD = ((decimal?)d.Element("CrossRateUSD"))
Only CurrencyName exists in all elements, sometimes we have elements like
<BanknoteBuying></BanknoteBuying>, some nodes do not carry the BanknoteBuying element at all.
Odd thing is I am getting a date/time parsing data error. So in short, casting it all to string works, but casting to appropriate nullable data type does not, data is well formed, and the local region is set correct to parse the decimal data.
<Currency Kod="RUB" CurrencyCode="RUB">
<Unit>1</Unit>
<Isim>RUS RUBLESİ</Isim>
<CurrencyName>RUSSIAN ROUBLE</CurrencyName>
<ForexBuying>0.05011</ForexBuying>
<ForexSelling>0.05077</ForexSelling>
<BanknoteBuying></BanknoteBuying>
<BanknoteSelling></BanknoteSelling>
<CrossRateUSD>30.5655</CrossRateUSD>
<CrossRateOther></CrossRateOther>