目的:取出某个section下的所有game,并将game的内容绑定到repeater控件
game.xml(文件太长,其中games下包含多个section,每个section下有多个game,所以只放这里一个game节点,这样设计有问题?):
    <?xml version="1.0" encoding="gb2312" ?>
    <games xmlns="http://tempuri.org/game.xsd">
<section sectionname="百科知识馆" listfile="index.aspx">
<game>
<gamename>我猜我猜我猜猜猜</gamename>
<smallpic>game14x.jpg</smallpic>
<bigpic>game14.jpg</bigpic>
                  </game>
         </section>
    </games>
x.aspx(不知道访问xml这样的思路对不对?):
                           string xmlpath=Server.MapPath("/xml/game.xml");
XPathDocument doc=new XPathDocument(xmlpath);
XPathNavigator nav=doc.CreateNavigator();
XPathNodeIterator iter=nav.Select("/games/section[@sectionname='百科知识馆']/game");

解决方案 »

  1.   

    怎么没人回答我啊,大家都不用xml吗?
      

  2.   

    可以用dataset
    DataSet ds=new DataSet();
    ds.ReadXml(Server.MapPath("/xml/game.xml"));
    this.repeater1.DataSource=ds.Tables["section"];
    this.repeater1.DataBind();
      

  3.   

    但这样的dataset是不对的:
    比如我有三个二级节点,六个三级节点,每个二级节点有两个三级节点,
    但生成的dataset中竟然只有两个表,一个section,一个game,
    game表六条数据六个三级节点,section三条数据三个二级节点,
    而我想要的是三个section表,各自有两条game记录
      

  4.   

    XmlNode node = doc.SelectSingleNode("games/section[@sectionname='百科知识馆']");
    node就是section节点
    foreach(XmlNode n in node.Nodes)
    {
        //你可以得到每个game}
      

  5.   

    不好意思,错了,应该是selectnodes方法具体语法可以参见msdn
      

  6.   

    XmlNodeList nodeList;
    XmlElement root = doc.DocumentElement;
    nodeList = root.SelectNodes("games/section[@sectionname='百科知识馆']");
    foreach (XmlNode node in nodeList)
    {
        //每个section的node
    }
      

  7.   

    错误提示:不包含对DocumentElement的定义