本帖最后由 liweizhe910 于 2014-12-20 20:11:58 编辑

解决方案 »

  1.   

                this.openFileDialog.ShowDialog();
                string MyFileName = this.openFileDialog.FileName;
                if (MyFileName.Trim() == "")
                    return;            if (File.Exists(MyFileName))
                {
                    string[] str = File.ReadAllLines(MyFileName, Encoding.Unicode); 
                }读取到数组str了……然后呢……?
      

  2.   

    然后写入到文件就可以了啊
    下面代码是写入文件的操作;
    文件路径是你要写入的文件路径;
      FileStream fs = new FileStream("文件路径", FileMode.Create);
                StreamWriter sw = new StreamWriter(fs);
                sw.WriteLine(message);
                sw.Close();
                fs.Close();
      

  3.   

    我想将含有“GCP label=”字符串的整行批量读取出来,然后将里面的“点名”,“高度”“经度”“纬度”“X”,“Y”,“Z”等等……单独提取出来
      

  4.   

    这是XML文件,用dataset 读取就可,
      

  5.   


       DataSet ds = new DataSet();
                ds.ReadXml("ntest.xml");
                StreamWriter sw = new StreamWriter("ntest.txt");            
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    string s1 = ds.Tables[0].Rows[i][0].ToString(); 
                    string s2 = ds.Tables[0].Rows[i][1].ToString(); 
                    string s3 = ds.Tables[0].Rows[i][2].ToString();
                    string s4 = ds.Tables[0].Rows[i][3].ToString();
                    sw.WriteLine(s1+" "+s2+" "+s3+" "+s4);
                }
                sw.Close();
      

  6.   

    如果只是读取 <GCP ......> 
     ds.Tables[0]--> ds.Tables["GCP"]
      

  7.   

    ds.ReadXml(MyFileName);运行到这一步的时候就出现了这样的错误提示:
    “System.Data.DuplicateNameException”类型的未经处理的异常在 System.Data.dll 中发生 
    其他信息: 无法添加名为“index”的列: 此 DataTable 中已存在同名的嵌套表。
    什么原因呢?谢谢!
      

  8.   

    提供了2个文件,
    http://pan.baidu.com/s/1jGyyYKu
    http://pan.baidu.com/s/1c0AM7o0
    谢谢帮忙查看……
      

  9.   


    换用方法:因dataset读取时,你文件中有2个index,所以出错了, XDocument item = XDocument.Load("tingkou2.xml");
                StreamWriter sw = new StreamWriter("ntest.txt");
                var result = from x in item.Descendants("GCP")
                             select new
                             {
                                 label = x.Attribute("label").Value,
                                 alt = x.Attribute("alt").Value,
                                 lat = x.Attribute("lat").Value,
                                 lng = x.Attribute("lng").Value,
                                 x = x.Attribute("x").Value,
                                 y = x.Attribute("y").Value                         };
                foreach (var el in result)
                {
                    //MessageBox.Show(el.label + " " + el.alt + " " + el.lat);
                    sw.WriteLine(el.label + " " + el.alt + " " + el.lat+" "+el.lng+" "+el.x+" "+el.y);
                }
                sw.Close();
      

  10.   

    如  y = x.Attribute("y").Value,属性你自己增加就可,
      

  11.   

    谢谢!完美解决!再问个小问题,
    我想读取完了之后展示其中一部分数据的话,
    需要用到什么控件呢?winform中!
      

  12.   


      var result = from x in item.Descendants("GCP")
                             select new
                             {
                                 label = x.Attribute("label").Value,
                                 alt = x.Attribute("alt").Value,
                                 lat = x.Attribute("lat").Value,
                                 lng = x.Attribute("lng").Value,
                                 x = x.Attribute("x").Value,
                                 y = x.Attribute("y").Value                         };
                dataGridView1.DataSource = result.ToList();
    这样就可把读取的数据都显示出来 了