//XML转DataSet public static void XmlToDataTableByFile(){ XmlDocument doc = new XmlDocument(); doc.Load(@"E:\\xmlsample.xml"); DataSet ds = new DataSet(); StringReader tr = new StringReader(doc.InnerXml); //DataTable也可以ReadXml() ds.ReadXml(tr); } //DataSet转XML public static void DataTableToXml(){ //获取DataSet数据 DataSet ds = XmlToDataTableByFile(); StringWriter sw = new StringWriter(); ds.Tables[0].WriteXml(sw); //XML字符串 string XmlStr =sw.ToString(); }
时间: 2024-10-08 09:21:44