pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

<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="rgk8uli" 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 中提取數(shù)據(jù)

        C# extracting data from XML(C# 從 XML 中提取數(shù)據(jù))
        • <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="8s2rpvp" 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 中提取數(shù)據(jù)的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我正在嘗試從 URL 中的 XML 讀取天氣數(shù)據(jù).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 中的預(yù)測數(shù)據(jù)感興趣.我想獲取時(shí)間和時(shí)間,然后是天氣數(shù)據(jù).例如溫度在 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"/>
                  

                  我想用這樣的方式提取數(shù)據(jù):

                  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);
                  

                  我創(chuàng)建了能夠讀取所有內(nèi)容的示例代碼,但我不知道如何僅提取我需要的數(shù)據(jù).我現(xiàn)在的代碼如下所示:

                  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;
                  
                              }
                          }
                  

                  有什么方法可以只提取天氣數(shù)據(jù)和時(shí)間嗎?

                  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;
                  }
                  

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

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

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

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

                  相關(guān)文檔推薦

                  Ignore whitespace while reading XML(讀取 XML 時(shí)忽略空格)
                  XML to LINQ with Checking Null Elements(帶有檢查空元素的 XML 到 LINQ)
                  Reading XML with unclosed tags in C#(在 C# 中讀取帶有未閉合標(biāo)簽的 XML)
                  Parsing tables, cells with Html agility in C#(在 C# 中使用 Html 敏捷性解析表格、單元格)
                  delete element from xml using LINQ(使用 LINQ 從 xml 中刪除元素)
                  Parse malformed XML(解析格式錯(cuò)誤的 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="dw8jwgm" id='ijaWZ'><tfoot id='ijaWZ'></tfoot><dl id='ijaWZ'><fieldset id='ijaWZ'></fieldset></dl></div>
                            主站蜘蛛池模板: 临沂招聘网_人才市场_招聘信息_求职招聘找工作请认准【马头商标】 | 首页_中夏易经起名网 | RV减速机-蜗轮蜗杆减速机-洗车机减速机-减速机厂家-艾思捷 | 排烟防火阀-消防排烟风机-正压送风口-厂家-价格-哪家好-德州鑫港旺通风设备有限公司 | 冰晶石|碱性嫩黄闪蒸干燥机-有机垃圾烘干设备-草酸钙盘式干燥机-常州市宝康干燥 | 企典软件一站式企业管理平台,可私有、本地化部署!在线CRM客户关系管理系统|移动办公OA管理系统|HR人事管理系统|人力 | 必胜高考网_全国高考备考和志愿填报信息平台 | 折弯机-刨槽机-数控折弯机-数控刨槽机-数控折弯机厂家-深圳豐科机械有限公司 | 分类168信息网 - 分类信息网 免费发布与查询| 冷却塔改造厂家_不锈钢冷却塔_玻璃钢冷却塔改造维修-广东特菱节能空调设备有限公司 | 气动调节阀,电动调节阀,自力式压力调节阀,切断阀「厂家」-浙江利沃夫自控阀门 | 合肥花魁情感婚姻咨询中心_挽回爱情_修复婚姻_恋爱指南 | 土壤有机碳消解器-石油|表层油类分析采水器-青岛溯源环保设备有限公司 | 聚合氯化铝-碱式氯化铝-聚合硫酸铁-聚氯化铝铁生产厂家多少钱一吨-聚丙烯酰胺价格_河南浩博净水材料有限公司 | 模切之家-专注服务模切行业的B2B平台! | 新疆乌鲁木齐网站建设-乌鲁木齐网站制作设计-新疆远璨网络 | 酒店品牌设计-酒店vi设计-酒店标识设计【国际级】VI策划公司 | 机构创新组合设计实验台_液压实验台_气动实训台-戴育教仪厂 | 大倾角皮带机-皮带输送机-螺旋输送机-矿用皮带输送机价格厂家-河南坤威机械 | 广东健伦体育发展有限公司-体育工程配套及销售运动器材的体育用品服务商 | 山楂片_雪花_迷你山楂片_山楂条饼厂家-青州市丰源食品厂 | 柔软云母板-硬质-水位计云母片组件-首页-武汉长丰云母绝缘材料有限公司 | 超细粉碎机|超微气流磨|气流分级机|粉体改性设备|超微粉碎设备-山东埃尔派粉碎机厂家 | 日本细胞免疫疗法_肿瘤免疫治疗_NK细胞疗法 - 免疫密码 | 双齿辊破碎机-大型狼牙破碎机视频-对辊破碎机价格/型号图片-金联机械设备生产厂家 | 山东聚盛新型材料有限公司-纳米防腐隔热彩铝板和纳米防腐隔热板以及钛锡板、PVDF氟膜板供应商 | 污泥烘干机-低温干化机-工业污泥烘干设备厂家-焦作市真节能环保设备科技有限公司 | 金现代信息产业股份有限公司--数字化解决方案供应商 | 高压包-点火器-高压发生器-点火变压器-江苏天网 | 自动螺旋上料机厂家价格-斗式提升机定制-螺杆绞龙输送机-杰凯上料机 | 档案密集柜_手动密集柜_智能密集柜_内蒙古档案密集柜-盛隆柜业内蒙古密集柜直销中心 | 环氧乙烷灭菌器_压力蒸汽灭菌器_低温等离子过氧化氢灭菌器 _低温蒸汽甲醛灭菌器_清洗工作站_医用干燥柜_灭菌耗材-环氧乙烷灭菌器_脉动真空压力蒸汽灭菌器_低温等离子灭菌设备_河南省三强医疗器械有限责任公司 | 培训中心-翰香原香酥板栗饼加盟店总部-正宗板栗酥饼技术 | 国产液相色谱仪-超高效液相色谱仪厂家-上海伍丰科学仪器有限公司 | 吸音板,隔音板,吸音材料,吸音板价格,声学材料 - 佛山诺声吸音板厂家 | 深圳货架厂_仓库货架公司_重型仓储货架_线棒货架批发-深圳市诺普泰仓储设备有限公司 | 轻型地埋电缆故障测试仪,频响法绕组变形测试仪,静荷式卧式拉力试验机-扬州苏电 | GAST/BRIWATEC/CINCINNATI/KARL-KLEIN/ZIEHL-ABEGG风机|亚喜科技 | EDLC超级法拉电容器_LIC锂离子超级电容_超级电容模组_软包单体电容电池_轴向薄膜电力电容器_深圳佳名兴电容有限公司_JMX专注中高端品牌电容生产厂家 | 引领中高档酒店加盟_含舍·美素酒店品牌官网 | 不锈钢酒柜|恒温酒柜|酒柜定制|酒窖定制-上海啸瑞实业有限公司 |