views:

42

answers:

2

hey I'm designing a car catalogue and need to use XML files for storage. In previous projecs, I was manually editing XML files with Linq. However, I came across XML serialization and am thinking this might be a better approach. Each item in the catalogue would be of type CarItem and contain various attributes. The catalogue can contain a few hundred cars and I'm worried about performance. If I deserialize the XML file, will all the CarItems be instantiated straight away? Is there a way for me to be able to choose which object gets deserialized based on parameters? For example, I'd like to say "if car color attribute is red, then only deserialize red CarItems into objects".

Thanks for any suggestions

+1  A: 

Yes, they all will be instantiated. However, few hundred objects is not a big deal for a class with some simple fields. Give it a try and check performance.

Kefir
Thanks for the reply. In that case, I'm hoping there may be a better approach than straight serializing/deserializing in order to be able to increase performance (since it's on a mobile device).
SSL
+1  A: 

There's quite a few posts with good examples of how you can control what you pull out and instantiate into objects/scalars using XDocument.

Shawn Oster's post in this thread I believe is quite close to what you want using linq. You can add where clauses to suit your requirements easily.

Mick N
That seems like it should do the job. Thanks for the help!
SSL
yw :) /15char..
Mick N