我想用C#读取xml 文件,存成一个txt 文档。
<grade>
<Class className="one">
  <Column StudentName="heery" score="90" subject="chinese" > </Column>
  <Column StudentName="jim" score="75" subject="math" > </Column>
  <Column StudentName="nancy" score="90" subject="chinese" > </Column>
...................
</Class><Class className="two">
  <Column StudentName="mike" score="90" subject="chinese" > </Column>
  <Column StudentName="lily" score="75" subject="math" > </Column>
  <Column StudentName="rose" score="90" subject="chinese" > </Column>
...................
</Class>
</grade>
怎样将以上格式的xml 读取成string?

解决方案 »

  1.   

    读完你还要处理么?
    如果不处理的话直接文件拷贝然后改名就可以了如果处理的话
    使用XmlDocument具体的要求说的详细点
      

  2.   

    XmlDocument.Save("xml.txt");没有明白你到要什么
    你的xml从哪里来的
      

  3.   


                StreamReader sr = new StreamReader(@"d:\a.xml");
                            StreamWriter a = File.CreateText(@"d:\a.txt");              a.Write(sr.ReadToEnd());
                sr.Close();
                a.Close();
      

  4.   

    读完要处理的,我倾向于用xmlReader
      

  5.   

    这是将xml文件存入数据库中:private void SaveDocument()
            {
                SqlConnection cn = new SqlConnection(@"连接字符串");
                FileInfo fi = new FileInfo(@"C:\200801110040004.xml");
                FileStream fs = fi.OpenRead();
                byte[] bytes = new byte[fs.Length];
                fs.Read(bytes, 0, Convert.ToInt32(fs.Length));
                fs.close();
                SqlCommand cm = new SqlCommand();
                cm.Connection = cn;
                cm.CommandType = CommandType.Text;
                cm.CommandText = "insert into  FileTable ( FileStr) values(@file)";
                SqlParameter spFile = new SqlParameter("@file", SqlDbType.Image);
                spFile.Value = bytes;
                cm.Parameters.Add(spFile);
                cn.Open();
                cm.ExecuteNonQuery();
                cn.Close();
            }
    这是从数据库中读,然后保存为txt文件:        private void GetDocument()
            {
                SqlConnection cn = new SqlConnection(@"连接字符串");
                SqlDataReader dr = null;
                SqlCommand cm = new SqlCommand();
                cm.Connection = cn;
                cm.CommandType = CommandType.Text;
                cm.CommandText = "select FileStr from FileTable  where ID=1";
                cn.Open();
                dr = cm.ExecuteReader();
                byte[] File = null;
                if (dr.Read())
                {
                    File = (byte[])dr[0];
                }
                cn.Close();
                FileStream fs;
                FileInfo fi = new System.IO.FileInfo(@"c:\myfile.txt");
                fs = fi.OpenWrite();
                fs.Write(File, 0, File.Length);
                fs.Close();
            }
      

  6.   

    处理应该用xmldocument+xpath把,最后保存的时候直接更改文件后缀即可
    xml是可以用文本格式才存放的
      xmldocument doc=new xmldocument();
      doc.load(@"d:\fsj.xml");
       
      xmlnode root=doc.documentElement;
      root.selectnodes/selectSinglenode();
      ... ...
      处理
      doc.save(@"c:\fsj.txt")
      
      

  7.   

    我想知道用xmlReader怎样读取!
    要取到各个节点,代码里还要做处理的!