這個問題必須是容易的,但我面臨的一個問題,這與我對付不了:的LINQ to XML:找不到.xml文件確切根
我下載的XML文件與天氣信息這種方式,請隨時通過以下鏈接來檢查它:
new WebClient().DownloadFile("http://export.yandex.ru/weather-ng/forecasts/72503.xml", directoryName);
var xml_file = XDocument.Load(directoryName);
,我需要從.xml
文件中得到一些數字:
string str_tweet = "Weather in New York: ";
foreach (XElement el in xml_file.Root.Elements())
{
if (el.Name == "fact")
{
MessageBox.Show("DID U FIND?");
str_tweet += "temperature " + (string)el.Element("temperature");
str_tweet += ", humidity " + (string)el.Element("humidity");
str_tweet += ", pressure " + (string)el.Element("pressure") +"torr";
str_tweet += ", wind power " + (string)el.Element("wind_speed") +".";
}
}
所以問題是,str_tweet
保持不變,和0123沒有顯示。所以實際上他沒有找到任何fact
根。我究竟做錯了什麼?
簡體.xml
文件看起來是這樣的:
<forecast ...>
<fact>
<observation_time>2014-07-06T03:51:00</observation_time>
<uptime>2014-07-06T04:36:15</uptime>
<temperature plate="fff28e" color="F7F3D3">18</temperature>
<wind_direction>calm</wind_direction>
.......
<fact>
......
</forecast>
做你的預測元素有一個名稱空間? –
@Selman22,老實說不明白你的問題,你的意思是什麼*預測元素*?無論如何,我猜不。 – Rocketq
我在問你是否在你的預測元素中有xmlns =「something」 –