tags:

views:

1051

answers:

3

Hi

Does anyone know what advantages (memory/speed) there are by using a class generated by the XSD tool to explore a deserialized XML file as opposed to XPATH?

A: 

The two are very different; but XmlSerializer will always deserialize entire objects; with XPath you can pick and choose. I'd use XmlSerializer personally, though - harder to get wrong.

XPath, however, is a complex beast that depends on the back-end. For example, XmlDocument (mutable) will behave differently to XPathDocument (read-only, optimized for query).

Marc Gravell
+2  A: 

I'd say the advantage is that you get a strongly typed class which is more convenient to use, and also the constructor for the class will throw an exception if the XML data in the file is invalid for creating the object, so you get a minimal data validation for free.

axel_c
Axel, you don't get a schema validation with the xmlserializer. The default deserialization is extremely quick and nasty. If you need validation, you need to suck your XML up through an XmlValidatingReader loaded with your schema first.
Spence
Agreed, I didn't mean full xsd validation though, but rather 'i can build an object of type x from this xml data' kind of validation. Edited my post to reflect that.
axel_c
+2  A: 

If you don't want to write boilerplate code, and you need to check ANY values of your XML on the way through, you can't go wrong with the XSD.exe generated classes.

Spence