如何把XML中的数据添加到哈希表中???
比如节点结果是这样的。<root>
  <FileList>
    <Node>
      <LocalPath>/NAND FLASH/FLASH/button/BT1.JPG</LocalPath>
      <RemotePath>/NAND FLASH/FLASH/button/BT1.JPG</RemotePath>
      <FileSize>15364</FileSize>
      <Version>2</Version>
    </Node>
</FileList>
</root>立马结贴立马结贴立马结贴立马结贴

解决方案 »

  1.   

    使用XMLDocument来读取XML数据
    string path = Server.MapPath("File/XMLFile.xml");
                XmlDocument doc = new XmlDocument();
                doc.Load(path);
      

  2.   

    HashTable保存的就是键值对,RemotePath保存在键中,/NAND FLASH/FLASH/button/BT1.JPG保存在Value中即可
    如果有多个列表,则可以嵌套保存
    建议使用Dictionary<string, Dictionary<string, string>>来保存。
    一个Node节点保存在Dictionary<string, string>中,然后该Dictionary<string, string>保存在上述集合中
      

  3.   


    Dictionary<string, Dictionary<string, string>> first = new Dictionary<string, Dictionary<string, string>>();
                Dictionary<string, string> child = null;
                int flag = 0;
                //循环XML列表
                flag++;
                child = new Dictionary<string, string>();
                child.Add("LocalPath", "/NAND FLASH/FLASH/button/BT1.JPG");
                child.Add("...","...");
                //...
                first.Add(flag.ToString(),child);//这里就添加了一个Node节点,然后接着循环获取其他Node节点内容
      

  4.   

    读取XML
    http://topic.csdn.net/u/20110210/16/913bfb37-3c3f-4852-9b39-029565c844ad.html
      

  5.   

     foreach (XmlNode Upnode in UpxmChild)//服务器
                                                    {
                                                        if (node.Name == "Version" && Upnode.Name == "Version")
                                                        {
                                                            if (!node.InnerText.Equals(Upnode.InnerText))//如果本机和服务器的版本号不一致
                                                            {
                                                                //添加到下载列表中
                                                                //DownTable.Add("Version", node.InnerText);
                                                                //DownTable.Add("FileSize", UpdateFileSize);
                                                                //DownTable.Add("LocalPath", UpdateLocalPath);
                                                                //DownTable.Add("RemotePath", UpdateRemotePath);                                                            child.Add("Version", node.InnerText);
                                                                child.Add("FileSize", UpdateFileSize);
                                                                child.Add("LocalPath", UpdateLocalPath);
                                                                child.Add("RemotePath", UpdateRemotePath);
                                                                first.Add("Node",child);
                                                            }
                                                            else //如果一致 循环删除服务器上的数据
                                                            {
                                                                first.Remove("Node");
                                                            }}不能循环给表中添加。他会提示已经存在键
      

  6.   

    键是不允许有重复的。所以在first.Add那里的键需要设为别的。
    int flag = 0;
    foreach (XmlNode Upnode in UpxmChild)//服务器
      {
      if (node.Name == "Version" && Upnode.Name == "Version")
      {
      if (!node.InnerText.Equals(Upnode.InnerText))//如果本机和服务器的版本号不一致
      {
      //添加到下载列表中
      //DownTable.Add("Version", node.InnerText);
      //DownTable.Add("FileSize", UpdateFileSize);
      //DownTable.Add("LocalPath", UpdateLocalPath);
      //DownTable.Add("RemotePath", UpdateRemotePath);
      flag ++ ;
      child.Add("Version", node.InnerText);
      child.Add("FileSize", UpdateFileSize);
      child.Add("LocalPath", UpdateLocalPath);
      child.Add("RemotePath", UpdateRemotePath);
      first.Add(flag.ToString(),child);
      }
      else //如果一致 循环删除服务器上的数据
      {
      first.Remove("Node");
      }}
      

  7.   

    读取的时候直接匹配就行了啊。
    ht[这里传你的键值].ToString();整个就返回你想要的了。