久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<i id='eg5pA'><tr id='eg5pA'><dt id='eg5pA'><q id='eg5pA'><span id='eg5pA'><b id='eg5pA'><form id='eg5pA'><ins id='eg5pA'></ins><ul id='eg5pA'></ul><sub id='eg5pA'></sub></form><legend id='eg5pA'></legend><bdo id='eg5pA'><pre id='eg5pA'><center id='eg5pA'></center></pre></bdo></b><th id='eg5pA'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='eg5pA'><tfoot id='eg5pA'></tfoot><dl id='eg5pA'><fieldset id='eg5pA'></fieldset></dl></div>
    <bdo id='eg5pA'></bdo><ul id='eg5pA'></ul>
  • <small id='eg5pA'></small><noframes id='eg5pA'>

      1. <legend id='eg5pA'><style id='eg5pA'><dir id='eg5pA'><q id='eg5pA'></q></dir></style></legend>
        <tfoot id='eg5pA'></tfoot>

      2. C# 從 XML 中提取數據

        C# extracting data from XML(C# 從 XML 中提取數據)
        • <bdo id='FshGd'></bdo><ul id='FshGd'></ul>
        • <i id='FshGd'><tr id='FshGd'><dt id='FshGd'><q id='FshGd'><span id='FshGd'><b id='FshGd'><form id='FshGd'><ins id='FshGd'></ins><ul id='FshGd'></ul><sub id='FshGd'></sub></form><legend id='FshGd'></legend><bdo id='FshGd'><pre id='FshGd'><center id='FshGd'></center></pre></bdo></b><th id='FshGd'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='FshGd'><tfoot id='FshGd'></tfoot><dl id='FshGd'><fieldset id='FshGd'></fieldset></dl></div>

              <tbody id='FshGd'></tbody>
          • <tfoot id='FshGd'></tfoot>

            <small id='FshGd'></small><noframes id='FshGd'>

              1. <legend id='FshGd'><style id='FshGd'><dir id='FshGd'><q id='FshGd'></q></dir></style></legend>

                  本文介紹了C# 從 XML 中提取數據的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在嘗試從 URL 中的 XML 讀取天氣數據.XML 如下所示:

                  I'm trying to read weather data from XML in a URL. The XML looks like this:

                  <weatherdata>
                  <location>...</location>
                  <credit>...</credit>
                  <links>...</links>
                  <meta>...</meta>
                  <sun rise="2013-05-11T04:49:22" set="2013-05-11T21:39:03"/>
                  <forecast>
                  <text>...</text>
                  <tabular>
                  <time from="2013-05-11T01:00:00" to="2013-05-11T06:00:00" period="0">
                  <!--
                   Valid from 2013-05-11T01:00:00 to 2013-05-11T06:00:00 
                  -->
                  <symbol number="2" name="Fair" var="mf/02n.03"/>
                  <precipitation value="0" minvalue="0" maxvalue="0.1"/>
                  <!--  Valid at 2013-05-11T01:00:00  -->
                  <windDirection deg="173.8" code="S" name="South"/>
                  <windSpeed mps="4.2" name="Gentle breeze"/>
                  <temperature unit="celsius" value="9"/>
                  <pressure unit="hPa" value="1004.2"/>
                  </time>
                  </tabular>
                  </forecast>
                  <observations>...</observations>
                  </weatherdata>
                  

                  我對 XML 中的預測數據感興趣.我想獲取時間和時間,然后是天氣數據.例如溫度在 XML 中是這樣寫的:

                  I am interested in the forecast data in the XML. I want to get the time from and time to, then the weather data. For example the temperature is written like this in the XML:

                  <temperature unit="celsius" value="9"/>
                  

                  我想用這樣的方式提取數據:

                  I want to extract the data with something like this:

                   string fromTime = time from(the attribute in the xml);
                                       string fromTime =time to(the attribute in the xml);
                                      string name = temperature(the attribute in the xml);
                                      string unit =unit(the attribute in the xml);
                                      int value = value(the attribute in the xml);
                  

                  我創建了能夠讀取所有內容的示例代碼,但我不知道如何僅提取我需要的數據.我現在的代碼如下所示:

                  I created sample code that is able to read everything but I don't know how to extract just the data I need. The code I have now looks like this:

                          String URLString = "http://www.yr.no/place/Norway/Oslo/Oslo/Oslo/forecast.xml";
                          XmlTextReader reader = new XmlTextReader(URLString);
                  
                          while (reader.Read())
                          {
                              switch (reader.NodeType)
                              {
                                  case XmlNodeType.Element: // The node is an element.
                                      Console.Write("" + reader.Name);
                  
                                      while (reader.MoveToNextAttribute()) // Read the attributes.
                                          Console.Write(" " + reader.Name + "='" + reader.Value + "'");
                                      Console.Write("
                  ");
                                      Console.WriteLine("------------------------------");
                                      break;
                                  case XmlNodeType.Text: //Display the text in each element.
                                      Console.WriteLine(reader.Value);
                                      break;
                                  case XmlNodeType.EndElement: //Display the end of the element.
                                      Console.Write("</" + reader.Name);
                                      Console.WriteLine(">");
                                      break;
                  
                              }
                          }
                  

                  有什么方法可以只提取天氣數據和時間嗎?

                  Any ideas how I can extract just the weather data and the time?

                  推薦答案

                  使用 LINQ to XML

                  Use LINQ to XML

                  XDocument X = XDocument.Load("http://www.yr.no/place/Norway/Oslo/Oslo/Oslo/forecast.xml");
                  
                  var forecast = X.Element("weatherdata").Element("forecast");
                  var location = forecast.Descendants("location").Attributes("name").FirstOrDefault().Value;
                  var tempData = forecast.Element("tabular").Elements("time");
                  
                  //This is what you need
                  var data = tempData.Select(item=>
                              new{
                                  from = Convert.ToDateTime(item.Attribute("from").Value),
                                  to = Convert.ToDateTime(item.Attribute("to").Value),
                                  temp = item.Element("temperature").Attribute("value").Value
                              });
                  
                  
                  //Or you can do a foreach if you need to
                  foreach (var item in tempData)
                  {
                          DateTime from = Convert.ToDateTime(item.Attribute("from").Value);
                          var temp = item.Element("temperature").Attribute("value").Value;
                  }
                  

                  我還沒有填寫所有內容.我希望您了解如何使用它.

                  I haven't populated everything. I hope you get the idea of how to use it.

                  這篇關于C# 從 XML 中提取數據的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Ignore whitespace while reading XML(讀取 XML 時忽略空格)
                  XML to LINQ with Checking Null Elements(帶有檢查空元素的 XML 到 LINQ)
                  Reading XML with unclosed tags in C#(在 C# 中讀取帶有未閉合標簽的 XML)
                  Parsing tables, cells with Html agility in C#(在 C# 中使用 Html 敏捷性解析表格、單元格)
                  delete element from xml using LINQ(使用 LINQ 從 xml 中刪除元素)
                  Parse malformed XML(解析格式錯誤的 XML)
                  • <small id='ijaWZ'></small><noframes id='ijaWZ'>

                        <tfoot id='ijaWZ'></tfoot>

                            <tbody id='ijaWZ'></tbody>
                          • <bdo id='ijaWZ'></bdo><ul id='ijaWZ'></ul>

                            <legend id='ijaWZ'><style id='ijaWZ'><dir id='ijaWZ'><q id='ijaWZ'></q></dir></style></legend>
                          • <i id='ijaWZ'><tr id='ijaWZ'><dt id='ijaWZ'><q id='ijaWZ'><span id='ijaWZ'><b id='ijaWZ'><form id='ijaWZ'><ins id='ijaWZ'></ins><ul id='ijaWZ'></ul><sub id='ijaWZ'></sub></form><legend id='ijaWZ'></legend><bdo id='ijaWZ'><pre id='ijaWZ'><center id='ijaWZ'></center></pre></bdo></b><th id='ijaWZ'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='ijaWZ'><tfoot id='ijaWZ'></tfoot><dl id='ijaWZ'><fieldset id='ijaWZ'></fieldset></dl></div>
                            主站蜘蛛池模板: 涩爱av一区二区三区 | 91视频一区二区三区 | 96国产精品久久久久aⅴ四区 | 国产一区二区三区在线 | 91麻豆产精品久久久久久 | 久久久久国产精品一区 | 亚洲 欧美 日韩在线 | 日日夜夜天天 | 国产一区在线免费 | 国产成人综合网 | 五月天激情综合网 | 区一区二区三在线观看 | 91大神xh98xh系列全部 | 精品在线一区二区三区 | 日韩精品久久久 | 久久综合久 | 在线观看视频一区二区三区 | 国产亚洲成av人在线观看导航 | 亚洲大片一区 | 精品日韩在线 | 91社区视频| 国产精品久久国产愉拍 | 久久国产精品色av免费观看 | 久久久久高清 | 久草福利 | 日本精品久久久久久久 | 国产大毛片| 午夜精品久久久久久久久久久久 | 久久高清 | 国产高清视频一区 | 国产一区二区三区免费观看在线 | 青青青伊人 | 草久在线视频 | 美女亚洲一区 | 日韩视频在线播放 | 亚洲视频免费在线观看 | 亚洲a在线观看 | 日日干天天操 | 欧美日韩国产在线 | 中文字幕欧美在线观看 | 久久精品欧美视频 |