【发布时间】:2020-04-14 21:05:06
【问题描述】:
我对使用 XML 文档还是很陌生。以前,我已经根据位置提取了我需要的值(“wCData”是加载的 XML 文档的变量):
sstring nowImageCode = wCData.ChildNodes.Item(1).ChildNodes.Item(8).Attributes.Item(2).Value;
但是,我认为位置可能已经改变,所以我需要一种方法来根据名称而不是位置将值分配给字符串。这是一个示例,其中城市被移除以获取象征性的安全性:
<current>
<city id="6666666" name="Timbuktu">
<coord lon="-79.34" lat="37.31"/>
<country>US</country>
<timezone>-18000</timezone>
<sun rise="2019-12-23T12:28:39" set="2019-12-23T22:03:57"/>
</city>
<temperature value="43.43" min="37.99" max="46.99" unit="fahrenheit"/>
<feels_like value="37.06" unit="fahrenheit"/>
<humidity value="61" unit="%"/>
<pressure value="1022" unit="hPa"/>
<wind>
<speed value="4.7" unit="mph" name="Light breeze"/>
<gusts/>
<direction value="40" code="NE" name="NorthEast"/>
</wind>
<clouds value="1" name="clear sky"/>
<visibility value="16093"/>
<precipitation mode="no"/>
<weather number="800" value="clear sky" icon="01d"/>
<lastupdate value="2019-12-23T15:01:55"/>
</current>
我需要提取的值是图标,在这种情况下是“01d”。
【问题讨论】:
标签: xml openweathermap