XML格式如下:
<?xml version="1.0" encoding="utf-8" ?> 
<configuration>
<Common>
<add key="CheckTimeSpan" value="20" />
</Common>
<DirInfo>
<DiR>
<Path>DirCount</Path>
<maxCount>20</maxCount>
<age>5</age>
</DiR>
<DiR>
<Path>DirCount1</Path>
<maxCount>200</maxCount>
<age>5</age>
</DiR>
</DirInfo>
</configuration>我想将所有DIR节点中的信息读出来,放到一个hashtable里去,hashtable的结构是:{path,{maxCount,age}}请大家教教我怎么写这个,解决即送分,谢谢!

解决方案 »

  1.   

    用GetElementsByTagName("DiR")方法得到一个数组
      

  2.   

    xmldoc.SelectNodes("configuration/DirInfo/*");
      

  3.   

    DataSet ds=new DataSet();
    ds.ReadXml(yourXml);
    DataTable dt=ds.Tables["DiR"];
    Hashtable ht=new Hashtable();
    foreach(DataRow dr in dt.Rows)
    {
    object[] obj={dr["maxCount"],dr["age"]};
    ht.Add(dr["Path"],obj);
    }
      

  4.   

    只是读取的话建议用XmlReader,不要用DOM
      

  5.   

    1.定位到DiR:XmlNodeList nodes = doc.SelectNodes("configuration/DirInfo/DiR");");
    2.提取每个节点
    hashtable htTarget = new hashtable();
    foreach (XmlNode node in nodes)
    {
        string path = node.ChildNode[0].Value;  
        string maxCount = node.ChildNode[1].Value;  
        string age = node.ChildNode[2].Value;  
        htTarget.add(path,new string[2] { maxCount , age  })
    }