C# 如何将Xml以c形式传递

C# 如何将Xml以c形式传递,c#,xml,C#,Xml,我已经试过很多次了,但都不行。我不知道怎么用c写 如何以c形式传递这些值 这是XML数据 <root> <location> <name>Kandy</name> <region>Central</region> <country>Sri Lanka</country> <lat>7.3</lat> <lon>80.64</lon> <tz_id&

我已经试过很多次了,但都不行。我不知道怎么用c写 如何以c形式传递这些值

这是XML数据

<root>
<location>
<name>Kandy</name>
<region>Central</region>
<country>Sri Lanka</country>
<lat>7.3</lat>
<lon>80.64</lon>
<tz_id>Asia/Colombo</tz_id>
<localtime_epoch>1506414825</localtime_epoch>
<localtime>2017-09-26 14:03</localtime>
</location>
</root>
此数据如何传递到c文本框中


你试了什么?你在哪里失败了?错误是什么?最重要的是,展示一些代码。否则,没有人能/将在这里帮助你。我不知道如何编码,请帮助我,任何人看看这个,jon skeet解释了如何改进你的问题,要在此网站上回答。getting error=XDocument无法找到名称空间如何添加名称空间var xmlText=KandyCentralSri Lanka7.380.64Asia/Colombo15064148252017-09-2614:03;XDocument XDocument=XDocument.ParsexmlText;字符串区域=xDocument.Root.Elementlocation.Elementregion.Value;只是复制过去
var xmlText = "<root><location><name>Kandy</name><region>Central</region><country>Sri Lanka</country><lat>7.3</lat><lon>80.64</lon><tz_id>Asia/Colombo</tz_id><localtime_epoch>1506414825</localtime_epoch><localtime>2017-09-2614:03</localtime></location></root>";
        XDocument xDocument = XDocument.Parse(xmlText);
        string region = xDocument.Root.Element("location").Element("region").Value;
regionTextBox.Text=region;



 but it will be nice  solution to create model then you can use this snippet

        public T Deserialize<T>(string input) where T : class
        {
            System.Xml.Serialization.XmlSerializer ser = new System.Xml.Serialization.XmlSerializer(typeof(T));

            using (StringReader sr = new StringReader(input))
            {
                return (T)ser.Deserialize(sr);
            }
        }