Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XMLDocument vs DataSet? Are They The Same Thing?

Tags:

c#

xml

dataset

Just a quick question.

Other than the way you manipulate them, are XMLDocuments and DataSets basically the same thing? I'm just wondering for speed issues.

I have come across some code that calls dataSet.getXML() and then traverses the new XMLDocument.

I'm just curious what's the performance difference and which is the best one to use!

Thanks,

Adam

like image 228
adamwtiko Avatar asked Jul 13 '10 12:07

adamwtiko


2 Answers

Very different.

A DataSet is a collection of related tabular records (with a strong focus on databases), including change tracking.

An XmlDocument is a tree structure of arbitrary data. You can convert between the two.

For "which is best".... what are you trying to do? Personally I very rarely (if ever) use DataSet / DataTable, but some people like them. I prefer an object (class) representation (perhaps via deserialization), but xml processing is fine in many cases.

It does, however, seem odd to write a DataSet to xml and then query the xml. In that scenario I would just access the original data directly.

like image 123
Marc Gravell Avatar answered Nov 01 '22 13:11

Marc Gravell


No they are not. A DataSet does not store its internal data in XML and than a XMLDocument does not use a table/row structure to store XML Elements. You can convert from one to the other within severe limits but that's it. One of the biggest limitations is that a DataSet requires data to fit in a strict Table/Column format where a XmlDocument can have a wildly different structure from one XmlElement to the next. Moreover, the hierarchical structure of a XmlDocument usually doesn't map well to the tabular structure of a DataSet.

.NET provides XmlDataDocument as a way handle XML data in a tabular way. You have to remember though that XmlDataDocument is an XmlDocument first. The generated DataSet is just an alternative and limited way to look at the underlying XML data.

like image 44
Panagiotis Kanavos Avatar answered Nov 01 '22 12:11

Panagiotis Kanavos