Import XML to Dataset or read XML using XPath?

1.2k Views Asked by At

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. To export, I'm using DataTable.WriteXml (c#) Now to read, what is best? 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? which performs best? I'm still learning xpath.

1

There are 1 best solutions below

1
On BEST ANSWER

Why not load the exported XML in using DataTable.ReadXml(fileName)? 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).

From an example in 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. If I'm misunderstanding your question, please let me know and I'll update accordingly.

I hope this helps.