條件Double.TryParse(node.ChildNodes [4] .InnerText,出課程)不起作用。它總是返回0。轉換XmlNode.InnerText到雙
foreach (XmlNode node in XmlDoc.SelectNodes("/ValCurs/Valute"))
{
if (node.ChildNodes[1].InnerText == curr_name) // CharCode
{
// throw new Exception(node.ChildNodes[4].InnerText); //returns 2.085 but the next condition doesn't work
if (Double.TryParse(node.ChildNodes[4].InnerText, out course)) // course value, nominal = 100
{
if (Int32.Parse(node.ChildNodes[2].InnerText) == 10) course *= 10; //for RUB, BYR nominal = 10
if (Int32.Parse(node.ChildNodes[2].InnerText) == 1000) course /= 10; //for JPY, HUF nominal = 1000
return course;
}
}
XML片段
<Valute id="1">
<NumCode>036</NumCode>
<CharCode>AUD</CharCode>
<Nominal>100</Nominal>
<Name>Australian dollars</Name>
<Value>1276.6300</Value>
</Valute>
總是回答「不工作」。此外,張貼XML的fragement。 – 2015-01-09 19:37:22
備註:使用[1]等訪問子節點非常脆弱。訂單改變時會發生什麼? – 2015-01-09 21:34:01