简体   繁体   English

将XML文件加载到DataTable(而不是从数据库)

[英]Load XML file into DataTable (not from a Database)

I'm looking into changing my application to load its xml format data files into DataTables (and a DataSet?) instead of deserializing them into classes. 我正在考虑更改我的应用程序以将其xml格式数据文件加载到DataTables(和DataSet?)而不是将它们反序列化为类。 I can generate a dataset using xsd.exe, but I'm not having any luck finding any examples showing how to use it. 我可以使用xsd.exe生成数据集,但我没有运气找到任何显示如何使用它的示例。

My Google searches have been hopelessly clogged with examples using xsd files as an intermediary in accessing database tables. 使用xsd文件作为访问数据库表的中介,我的Google搜索无可救药地被阻塞。 Since my apps saving data files instead of querying a DB these aren't of any use to me. 由于我的应用程序保存数据文件而不是查询数据库,因此对我来说没有任何用处。

Try out with. 尝试一下。 May be you need to format your xml. 可能是你需要格式化你的xml。

    DataSet ds = new DataSet();
    ds.ReadXml("xml file path");

Is manually filling the schema and table an option? 手动填充架构和表是一个选项吗?

DataTable table = new DataTable();
table.ReadXmlSchema(xmlReader);
table.ReadXml(xmlReader);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM