adamwtiko
adamwtiko

Reputation: 2905

XMLDocument vs DataSet? Are They The Same Thing?

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

Upvotes: 5

Views: 1952

Answers (3)

Dested
Dested

Reputation: 6433

Depending on the size of your tables linq to xml or xquery might be faster to query your data than looking through the table. Im not positive on this, it is something you are going to have to test against your own data.

Upvotes: 0

Panagiotis Kanavos
Panagiotis Kanavos

Reputation: 131483

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.

Upvotes: 2

Marc Gravell
Marc Gravell

Reputation: 1062975

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.

Upvotes: 9

Related Questions