//测试方法
public static DataTable test()
{
string savePath = System.AppDomain.CurrentDomain.BaseDirectory;
string path="";
path=savePath+"/manager/wenjian.xml";
XmlDocument doc = new XmlDocument();
doc.Load(path);
string str = doc.InnerXml;
DataTable dt = XmlToDataTable(str);
return dt;
}
//xml 转DataTable
public static DataTable XmlToDataTable(string xmlStr)
{
if (!string.IsNullOrEmpty(xmlStr))
{
StringReader StrStream = null;
XmlTextReader Xmlrdr = null;
try
{
DataSet ds = new DataSet();
StrStream = new StringReader(xmlStr);
Xmlrdr = new XmlTextReader(StrStream);
ds.readxml(Xmlrdr);
return ds.Tables[0];
}
catch (Exception e)
{
return null;
}
finally
{
if (Xmlrdr != null)
{
Xmlrdr.Close();
StrStream.Close();
StrStream.dispose();
}
}
}
return null;
}
//DataTable 转 xml public static void DataTabletoXml(DataTable vTable) { string savePath = System.AppDomain.CurrentDomain.BaseDirectory; if (!Directory.Exists(savePath)) { Directory.CreateDirectory(savePath); } string xml = savePath + @"\my.xml"; if (File.Exists(xml)) { File.Delete(xml); } vTable.WriteXml(savePath + @"\my.xml"); }