怎样将以上格式的xml 读取成string?
我想用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?
[解决办法]
这是将xml文件存入数据库中:
- C# code
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(); }
[解决办法]
处理应该用xmldocument+xpath把,最后保存的时候直接更改文件后缀即可
xml是可以用文本格式才存放的
xmldocument doc=new xmldocument();
doc.load(@"d:\fsj.xml");
xmlnode root=doc.documentElement;
root.selectnodes/selectSinglenode();
... ...
处理
doc.save(@"c:\fsj.txt")