看到别人blog上的xml 
上面有个<rss version =2.0></rss>
这个是怎么弄出来的  答对有赏-<rss version=2.0>//我想弄出这级目录

解决方案 »

  1.   

    属于Attribute...举个例子:
    <?xml version="1.0" encoding="gb2312"?>
    <bookstore>
      <book genre="fantasy" ISBN="2-3631-4">
        <title>Oberon's Legacy</title>
        <author>Corets, Eva</author>
        <price>5.95</price>
      </book>
    </bookstore>读取所有数据:
    XmlDocument xmlDoc=new XmlDocument();
    xmlDoc.Load("bookstore.xml");
    XmlNode xn=xmlDoc.SelectSingleNode("bookstore");
     
       XmlNodeList xnl=xn.ChildNodes;
       
       foreach(XmlNode xnf in xnl)
       {
        XmlElement xe=(XmlElement)xnf;
        Console.WriteLine(xe.GetAttribute("genre"));//显示属性值
        Console.WriteLine(xe.GetAttribute("ISBN"));
     
        XmlNodeList xnf1=xe.ChildNodes;
        foreach(XmlNode xn2 in xnf1)
        {
         Console.WriteLine(xn2.InnerText);//显示子节点点文本
        }
       }
      

  2.   

    对于你的Xml,你就先找到<rss>结点..然后xmlElement.GetAttribute("version");
      

  3.   

    private void xml()
    {
    XmlDocument xmlDoc=new XmlDocument();

    xmlDoc.Load(Server.MapPath("../xml/bookstore.xml"));

    XmlNode xn=xmlDoc.SelectSingleNode("bookstore");
     
    XmlNodeList xnl=xn.ChildNodes;
       
    foreach(XmlNode xnf in xnl)
    {
    XmlElement xe=(XmlElement)xnf;
    Console.WriteLine(xe.GetAttribute("genre"));//显示属性值

     
    XmlNodeList xnf1=xe.ChildNodes;
    foreach(XmlNode xn2 in xnf1)
    {
    Console.WriteLine(xn2.InnerText);//显示子节点点文本
    }
    }
    XmlTextWriter xw = new XmlTextWriter(Server.MapPath("rss3.xml"), Encoding.UTF8); }
    出错了 文件第一行  40出错
      

  4.   

    我不知道你什么情况,我是这么做的:
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Threading;
    using System.IO;
    using System.Web;
    using System.Xml;namespace TestConsole
    {
        class Program
        {
            static void Main(string[] args)
            {
                xml();
            }
            public static void xml()
            {
                XmlDocument xmlDoc = new XmlDocument();            xmlDoc.Load("../../bookstore.xml");            XmlNode xn = xmlDoc.SelectSingleNode("bookstore");            XmlNodeList xnl = xn.ChildNodes;            foreach (XmlNode xnf in xnl)
                {
                    XmlElement xe = (XmlElement)xnf;
                    Console.WriteLine(xe.GetAttribute("genre"));//显示属性值
                    XmlNodeList xnf1 = xe.ChildNodes;
                    foreach (XmlNode xn2 in xnf1)
                    {
                        Console.WriteLine(xn2.InnerText);//显示子节点点文本
                    }
                }
            }    }
    }
    bookstore.xml文件与"Program.cs"在同一目录下...
    输出如下:fantasy
    Oberon's Legacy
    Corets, Eva
    5.95
    请按任意键继续. . .