<?xml version="1.0" encoding="utf-8" ?>
<game>
  <gameinfo value = "eq">  
<datainfo>
<table>report</table>
<baktable>report</baktable>
<type>0</type>
<database>eq</database>
<username>eq</username>
<password>123</password>
<totb>0.95</totb>
<set id="1"/>
<set id="2"/>
<set id="3"/>  </datainfo>  </gameinfo>
  <gameinfo value = "eq1">  
<datainfo>
<table>report</table>
<baktable>report</baktable>
<type>1</type>
<username>1</username>
<password>1</password>
<totb>1</totb>
<set id="1"/>
<set id="2"/>
<set id="3"/>
         </datainfo>
  </gameinfo>
</game>这个如何取datainfo中的值和下面id中的值  不同id的值需要放在不同的arrlist中 给个具体代码谢谢了

解决方案 »

  1.   

    datainfo中的值 需要存在dataset中
      

  2.   

    写一个类去读XML 文件 
    然后给DATASET 就行
      

  3.   

    没明白什么意思
    你要是读节点,可以用xpath
    这样比较灵活
    想弄成什么格式的都行比如
    XmlDocument doc = new XmlDocument();//构造doc
    XmlNodeList list = doc.SelectNodes("game/gameinfo");
    这个list里面就是两个gameinfo 的节点集合
    接下来你想怎么分就怎么分啊
      

  4.   

    使用命名空间System.xml
    昨天刚做了一个遍历xml然后映射到树性空间的demo
    //打开一个xml文件
    public bool OpenXmlDoc()
    {
    try
    {
    if(!m_bOpenStat)
    {
    m_xmlDoc=new XmlDocument();
    m_xmlDoc.Load((m_strXmlPath.Equals(string.Empty))?"config\\Appcfg.xml":m_strXmlPath);
    }

    m_bOpenStat=true;
    }
    catch(Exception ex)
    {
    return false;
    } return true;
    }
    //读取元素内容和属性 public string GetElementAttr(string eleName)
    {
    if(!m_bOpenStat) OpenXmlDoc(); string strValue=string.Empty; XmlNodeList lst=m_xmlDoc.GetElementsByTagName(eleName); strValue=(lst.Item(0).InnerText==null)?string.Empty:lst.Item(0).InnerText;
    System.Xml.XmlAttributeCollection cols=lst.Item(0).Attributes;

    foreach(System.Xml.XmlAttribute attr in cols)
    { } return strValue; }//解析xmlDoc
    public void ListDoc(System.Xml.XmlDocument xmlDoc)
    {
    System.Xml.XmlNodeList nodeLst=xmlDoc.ChildNodes;

    foreach(System.Xml.XmlNode node in nodeLst)
    {
    if(node.NodeType==XmlNodeType.Element)
    ListNodes(null,node);
    }
    } public void ListNodes(System.Windows.Forms.TreeNode parentTreeViewNode,System.Xml.XmlNode node)
    {
    if(node.NodeType!=XmlNodeType.Element) return;
    TreeNode tnode=new TreeNode(node.Name);
    if(parentTreeViewNode!=null)
    parentTreeViewNode.Nodes.Add(tnode);
    else
    this.tvw_Xml.Nodes.Add(tnode);
    foreach(System.Xml.XmlNode childNode in node.ChildNodes)
    {
    ListNodes(tnode,childNode);
    }
    }----------
    看看这几个类吧
    XmlDocument
    XmlNode 
    XmlAttribute
    主要步骤
    1 打开xml文件 m_xmlDoc=new XmlDocument();
                  m_xmlDoc.Load("menu.xml");
    2 获得一个元数
                 XmlNodeList lst=m_xmlDoc.GetElementsByTagName(eleName);   //eleName比如数是gameinfo 
    3 在第二步lst中,遍历,
       System.Xml.XmlAttributeCollection cols=lst.Item(0).Attributes;//可以获得属性集
       根据value属性<gameinfo value = "eq"> 匹配的元素
    4 获得子元数集node.ChildNodes
       
      如此向下
      

  5.   

    dataset ds=new dataset()
    ds.readxml("aa.xml")
    然后操作这个ds不用教了吧
      

  6.   

    meixiaofeng(亲爱的) 偶现在就是不会操作ds了 ds读进去以后有3个表 偶比较菜不知道怎么区分不同记录了
      

  7.   

    忘了具体的了可以区别不同的  Name 吧如  Name == "baktable" 
    是否可以将  report 这个 InnerText取出来
      

  8.   

    我想做的就是读当前XML文件的时候 把<table>report</table><baktable>report</baktable>
    <type>0</type><database>eq</database><username>eq</username><password>123</password><totb>0.95</totb>值取出来存到变量中去 然后把所有set id 的值放进一个arraylist中
      

  9.   

    补充下 是gameinfo value = "eq" 下的记录
      

  10.   

    string path = "a.xml";
    XmlDocument doc = new XmlDocument();
    doc.Load(path);
    string table = doc.SelectSingleNode("game/gameinfo[@value='eq']/datainfo/table").InnerText;
    string baktable = doc.SelectSingleNode("game/gameinfo[@value='eq']/datainfo/baktable").InnerText;
    .........
    XmlNodeList list = doc.SelectNodes("game/gameinfo[@value='eq']/datainfo/set");
    ArrayList set = new ArrayList();
    foreach(XmlNode temp in list)
    {
        set.Add(temp.Attributes["id"].Value)
    }
    上面的字符串我只是举了两个例子
    后面的set这个arraylist就是你想要得所有set节点的属性的值
      

  11.   

    用这种path的方法,比较灵活
    可以方便的根据你的需要
    得到你想要得值