C#:如何在文本框中获取xml值?

C#:如何在文本框中获取xml值?,c#,c#-3.0,c#-2.0,C#,C# 3.0,C# 2.0,我有一个XML文件 <current> <city> <country>JAPAN</country> </city> <temperature value="307.07" min="307.07" max="307.07" unit="kelvin"/> </current> 使用xml linq: using System; using System.Collections.Generic; using

我有一个XML文件

<current>
<city>
<country>JAPAN</country>
</city>
<temperature value="307.07" min="307.07" max="307.07" unit="kelvin"/>
</current>
使用xml linq:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        const string FILENAME = @"c:\temp\test.xml";
        static void Main(string[] args)
        {
            string xml = File.ReadAllText(FILENAME);

            XDocument doc = XDocument.Parse(xml);

            decimal temperature = (decimal)doc.Descendants("temperature").First().Attribute("value");
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        const string FILENAME = @"c:\temp\test.xml";
        static void Main(string[] args)
        {
            string xml = File.ReadAllText(FILENAME);

            XDocument doc = XDocument.Parse(xml);

            decimal temperature = (decimal)doc.Descendants("temperature").First().Attribute("value");
        }
    }
}