如何使用C#将XMl文件转换为DataTable而不将XML文件保存到本地驱动器
问题描述:
大家好,
有什么方法可以将XML文件读取到在运行时创建的数据表中,而不将XML文件保存到本地驱动器中吗?
另请参见 [ ^ ]
Hi all,
Is there any way to read the XML file into datatable which is creating in runtime ,without saving xml file into local drive?
See Here also[^]
答
DataSet ds = new DataSet();
ds.ReadXml(new XmlTextReader(new StringReader(xml)));
DataTable books = ds.Tables[0];
或
OR
XmlDocument xdoc = MethodReturnsXmlDocument();
DataSet ds = new DataSet()
ds.ReadXml(new XmlNodeReader(xdoc));