我已經使用天氣API以XML格式返回溫度值並將它們寫入文本文件。我的下一步是從我的程序中讀取XML文件中的值。這是值的格式;從C#中讀取XML中的特定值
<temperature value="21.37" min="18.89" max="22.78" unit="metric">
</temperature>
<humidity value="68" unit="%">
</humidity>
<pressure value="1019" unit="hPa">
</pressure>
我想訪問的溫度值,但我不確定該怎麼做,通過從文本文件閱讀特別是考慮到文本文件是比我需要長得多。訪問我想要的值最有效的方式是什麼?
編輯:
<current>
<city id="" name="">
<coord lon="-0.45" lat="52.19">
</coord>
<country>GB</country>
<sun rise="2016-08-16T04:48:13" set="2016-08-16T19:22:26">
</sun>
</city>
<temperature value="22.06" min="19.44" max="23.89" unit="metric">
</temperature>
<humidity value="67" unit="%">
</humidity>
<pressure value="1019" unit="hPa">
</pressure>
<wind>
<speed value="2.57" name="Light breeze">
</speed>
<gusts value="6.17">
</gusts>
<direction value="73" code="ENE" name="East-northeast">
</direction>
</wind>
<clouds value="24" name="few clouds">
</clouds>
<visibility>
</visibility>
<precipitation mode="no">
</precipitation>
<weather number="801" value="few clouds" icon="02d">
</weather>
<lastupdate value="2016-08-16T10:44:02">
</lastupdate>
</current>
我得到這個方法的錯誤'附加信息:在根級別的數據是無效的。第1行,位置1'。我已經用完整的XML文件更新了我的問題。 – CBreeze
@CBreeze - 我現在已經在給定的xml上執行了兩個代碼段,這很好。你確定輸出目錄中的xml是一樣的嗎? –