2017-09-26 7 views
-2

私は何度も試したことがありませんでした。私は私が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>Asia/Colombo</tz_id> 
<localtime_epoch>1506414825</localtime_epoch> 
<localtime>2017-09-26 14:03</localtime> 
</location> 
</root> 

このデータであるC#のフォームでこの値を渡すことができますどのようにC#の でそれを記述する方法がわからない

enter image description here

+2

何を試しましたか?あなたはどこで失敗しましたか?エラーは何ですか?最も重要なのは、いくつかのコードを表示することです。そうでなければ誰もあなたをここで助けてくれません。 – Smartis

+0

私はそれをコード化する方法がわかりません –

+1

はこの[リンク]を見てください(https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question) /)ここで、* jon skeet *はあなたの質問を改善し、このサイトで答える方法を説明しています。 – LuckyLikey

答えて

-1
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); 
      } 
     } 
+0

取得エラー= XDocumentは、名前空間に= "

+0

するvar XMLTEXTを追加する方法ネームスペースを見つけることができませんでしたキャンディ中央スリランカ 7.3 80.64アジア/コロンボ 1506414825 2017-09-2614:03 "; XDocument xDocument = XDocument.Parse(xmlText); string region = xDocument.Root.Element( "location")。要素( "region")。値。 –

+0

コピー&ペースト –

関連する問題