5

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

3 Answers 3

9

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.

3
  • I'm attempting to traverse through a DataSet and want to keep it inline with the rest of the code. I'm returned a DataSet from a third party DLL and was just curious about the performance differences
    – adamwtiko
    Jul 13, 2010 at 12:26
  • @Adam - the "performance differences" are going to be specific to your usage. You may want to profile, but first: does it work and is it fast enough. If so.... perhaps let it be? Jul 13, 2010 at 12:28
  • I just did a few little tests and I think you're right, leaving it be may be the best bet. I have a DataSet that is well formed ready to traverse with very few lines of code versus the need to convert to an XMLDocument and navigate. Thanks.
    – adamwtiko
    Jul 13, 2010 at 12:43
2

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.

0

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.

1
  • I'd love to use LINQ in some shape or form but the project is .NET 2.0 and I'm bound to the current assemblies I have! Thanks for the reply though, I'm a big fan of LINQ though :)
    – adamwtiko
    Jul 13, 2010 at 12:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.