简体   繁体   English

将XML导入数据集或使用XPath读取XML?

[英]Import XML to Dataset or read XML using XPath?

I'd like to know what is the best practice. 我想知道什么是最佳做法。 I'm exporting some data (tables) from my database to XML files so I can read my data from them. 我正在将一些数据(表)从数据库导出到XML文件,以便可以从中读取数据。 To export, I'm using DataTable.WriteXml (c#) Now to read, what is best? 要导出,我正在使用DataTable.WriteXml(c#)现在阅读,什么是最好的? to import them into a dataset and use DataTable.Select to get the row I want or create an XPathDocument and use XPath to get the data? 将它们导入数据集中并使用DataTable.Select来获取所需的行,还是创建XPathDocument并使用XPath来获取数据? which performs best? 哪个表现最好? I'm still learning xpath. 我还在学习xpath。

Why not load the exported XML in using DataTable.ReadXml(fileName) ? 为什么不使用DataTable.ReadXml(fileName)加载导出的XML? If you exported your table data using DataTable.WriteXml(file, XmlWriteMode.XmlSchema) , then you can import it in to a new DataTable using ReadXml(file) . 如果使用DataTable.WriteXml(file, XmlWriteMode.XmlSchema)导出表数据,则可以使用ReadXml(file)将其导入到新的DataTable

From an example in MSDN: 从MSDN中的示例:

myOldTable.WriteXml(fileName, XmlWriteMode.WriteSchema);

DataTable newTable = new DataTable();
newTable.ReadXml(fileName);

If that's the case, I don't see where you'd need XPath. 如果是这样,我看不到您需要XPath的地方。 If I'm misunderstanding your question, please let me know and I'll update accordingly. 如果我误解了您的问题,请告诉我,我会相应地进行更新。

I hope this helps. 我希望这有帮助。

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

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