如有一个xml文件DownData.xml,内容如下
<?xml version="1.0" standalone="yes"?> <Root> <Downloads>1339</Downloads> <Consumption>1223381</Consumption> <Rebate>207977.26</Rebate> </Root>
读取数据
private void GetInfo() { DataSet ds = new DataSet(); string strXmlPath = Server.MapPath("~/config/DownData.xml");//xml路径 ds.ReadXml(strXmlPath); string downStr= ds.Tables[0].Rows[0]["Downloads"].ToString(); string conStr= ds.Tables[0].Rows[0]["Consumption"].ToString(); string reStr= ds.Tables[0].Rows[0]["Rebate"].ToString(); }
修改数据
protected void Change() { DataSet ds = new DataSet(); string strXmlPath = Server.MapPath("~/config/DownData.xml"); ds.ReadXml(strXmlPath); ds.Tables[0].Rows[0]["Downloads"] ="2000"; ds.Tables[0].Rows[0]["Consumption"] = "1000000"; ds.Tables[0].Rows[0]["Rebate"] = "122444"; ds.AcceptChanges(); //写入xml ds.WriteXml(strXmlPath); }