我现在有一个XML文档如下:
<info>
  <news>
    <title>娱乐新闻</title>
    <about>乱写也没关系,现在</about>
    <url>http://www.communion.cn</url>
    <author>admin</author>
    <time>2006-1-24 13:39:01</time>
  </news>
  <news>
    <title>技术文章</title>
    <about>技术在线,先给钱钱再说!</about>
    <url>http://www.communion.cn</url>
    <author>admin</author>
    <time>2006-1-24 14:56:46</time>
  </news>
  <news>
    <title>无聊事情sdfasdf</title>
    <about>asdfasdfasd</about>
    <url>http://www.communion.cn</url>
    <author>admin</author>
    <time>2006-1-24 15:16:09</time>
  </news>
</info>
我用这个取出了节点总数:int count=xmlDoc.DocumentElement.ChildNodes.Count;
现在我想用什么方法显示出我任意的一个节点,也就是不要显示第一个,我要显示第二个,第三个的!

解决方案 »

  1.   

    int count=xmlDoc.DocumentElement.ChildNodes.Count
    for(int i = 0;i<count;i++)
    {
    if(i>0)
    //显示
    }
    另外也可以用xpath
    XmlNodeList nodes = xmlDoc.SelectNodes("/info/new[position() > 1]");
    for(int i = 0;i<nodes.Count;i++)
    {
    //显示
    }
      

  2.   

    TO:net_lover(孟子E章) 这样可不可以的啊?XmlDocument xmlDoc=new XmlDocument();
    xmlDoc.Load("/Inetpub/wwwroot/Web/SendRss/news.xml");
    int count=xmlDoc.DocumentElement.ChildNodes.Count;//取节点个数
    // XmlNode xn=xmlDoc.SelectSingleNode("news");
    for(int i=0;i<count;i++)
    {
    XmlNode title=xmlDoc.SelectSingleNode("//title[position()=i]");
    XmlNode about=xmlDoc.SelectSingleNode("//about[position()=i]");
    XmlNode url=xmlDoc.SelectSingleNode("//url[position()=i]");
    XmlNode author=xmlDoc.SelectSingleNode("//author[position()=i]");
    XmlNode time=xmlDoc.SelectSingleNode("//time[position()=i]");
          Response.Write("标题是:"+title.InnerText+"正文:"+about.InnerText+" URL地址:"+url.InnerText+"作者:"+author.InnerText+"发布时间:"+time.InnerText);
    }
      

  3.   

    大家帮我看一下啊?我想用这样的循环显示出节点的内容!~~
    XmlDocument xmlDoc=new XmlDocument();
    xmlDoc.Load("/Inetpub/wwwroot/Web/SendRss/news.xml");
    int count=xmlDoc.DocumentElement.ChildNodes.Count;//取节点个数
    // XmlNode xn=xmlDoc.SelectSingleNode("news");
    for(int i=0;i<count;i++)
    {
    XmlNode title=xmlDoc.SelectSingleNode("//title[position()=i]");
    XmlNode about=xmlDoc.SelectSingleNode("//about[position()=i]");
    XmlNode url=xmlDoc.SelectSingleNode("//url[position()=i]");
    XmlNode author=xmlDoc.SelectSingleNode("//author[position()=i]");
    XmlNode time=xmlDoc.SelectSingleNode("//time[position()=i]");
          Response.Write("标题是:"+title.InnerText+"正文:"+about.InnerText+" URL地址:"+url.InnerText+"作者:"+author.InnerText+"发布时间:"+time.InnerText);
    }
    可是这样写有点问题?我跟踪看了一下发现title这些显示的是无定义值的
      

  4.   

    XmlNode title=xmlDoc.SelectSingleNode("//title[position()=" + i.ToString() + "]");