我想用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?
<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?
解决方案 »
- winio.dll的问题
- using Microsoft.Office.Interop.Excel时报错,急~~
- 我做了一个activex,然后又做了一个安装包,但使用时需要数字签名才能安装,不知道谁能告诉我怎么给安装包加签名。
- 如何将DAO层的方法做成存储过程执行??
- 自学C#求指教
- 多线程绑定DataGridView的问题
- 如何修改一个文本文件中的几行数据?
- 如何判断一个string的每个字符都是0-9或a-f或A-F?即为十六进制数?
- C# 书籍
- 我写的一个注册用户名的页面,跟数据库加一个用户,但是点机,不包错也不增加用户,请看看!!
- c#如何让键盘失效~
- c# 如何获取Win2003中的已连接用户名称,怎样断开一个已连接用户?
如果不处理的话直接文件拷贝然后改名就可以了如果处理的话
使用XmlDocument具体的要求说的详细点
你的xml从哪里来的
StreamReader sr = new StreamReader(@"d:\a.xml");
StreamWriter a = File.CreateText(@"d:\a.txt"); a.Write(sr.ReadToEnd());
sr.Close();
a.Close();
{
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();
}
xml是可以用文本格式才存放的
xmldocument doc=new xmldocument();
doc.load(@"d:\fsj.xml");
xmlnode root=doc.documentElement;
root.selectnodes/selectSinglenode();
... ...
处理
doc.save(@"c:\fsj.txt")
要取到各个节点,代码里还要做处理的!