从xmldocument读取节点 [英] reading nodes from an xmldocument

查看:83
本文介绍了从xmldocument读取节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我想知道如何阅读xml文档.
xml的结构如下...

hello all, i was wondering how i could read through a xml document.
The structure of the xml is as follows...

<response>
 <forecast>
  <txt_forecast>
  </txt_forecast>
  <simpleforecast>
   <forecastdays>
    <forecastday>
      <day>tuesday</day>
      <tempF>100</tempF>
      <tempC>40</tempC>
    </forecastday>
    <forecastday>
       <day>...
       <tempF>
        .....
    </forecastday>
   </forecastdays>
  </simpleforecast>
 </forecast>
</response>



现在我选择了我最关心的Forecastdays节点...像



now i have selected the forecastdays node which is of main concern to me... like

XmlDocument xmlForecast = new XmlDocument();
        xmlForecast.Load(string.Format("http://adfm.com/api/aasdfadf3/forecast/q/np/{0}", strCityName));

if (xmlForecast.SelectSingleNode("/response/error") != null)
            {
                condition.Error = xmlForecast.SelectSingleNode("/response/error/description").InnerText;
            }
            else if(xmlForecast.SelectSingleNode("/response/forecast/simpleforecast/forecastdays")!=null)
            {

                
                
            }



现在我要做的就是遍历
内部存在的所有Forecastday节点 响应/预测/简单预测/预测日....并将其存储在通用列表中.
我如何进行迭代?我只想知道如何迭代...在存储字典或列表< string>之后没问题.

预先感谢,
Minghang



now all i want to do is iterate through all the forecastday nodes present inside the
response/forecast/simpleforecast/forecastdays....and store it in a generic list.
How do i do the iteration?? i just want to know how to iterate...after that storing a dictionary or a list<string> will be no problem.

Thanks in advance,
Minghang

推荐答案

在下面使用for循环遍历预测日以获取每个预测日
use below for loop to iterate through forecastdays to get each forecastday
else if (xmlForecast.SelectSingleNode("/response/forecast/simpleforecast/forecastdays") != null)
            {
                XmlNodeList forecastdays = xmlForecast.SelectSingleNode("/response/forecast/simpleforecast/forecastdays").ChildNodes;
                foreach (XmlNode forecastday in forecastdays)
                {

                }
            }


这篇关于从xmldocument读取节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆