tags:

views:

434

answers:

3

What is the best way to store XML data used in a program ? Use RESX file or store it as a .xml file and load and unload the files as per requirement

+1  A: 

.resx files are XML files albeit conforming to a particular schema (Microsoft ResX Schema v2.0). This schema was designed with the explicit aim of being easily human readable and editable manually.

I see no problem with storing your data as XML files. Basically it depends on the function of the data - If it is localizable resources that you are trying to store, go with the established .resx files. If not, you are free to use your XML with custom schema.

Cerebrus
+2  A: 

A third option would be to put the XML file as embedded resource in the assembly. In that case, use Assembly.GetManifestResourceStream() to load the XML.

As Cerebrus wrote, when localization is necessary, RESX would be the way to go.

Sven Künzler
let s say I have a very huge xml file and put it into the resx file, In that case the whole file is loaded to the memory(ram) every time the dll is loaded and till the time it is not unloaded. Is this not a n overhead ?
Siddharth
For large and/or many files that would be a downside indeed. AFAIK, ressources are loaded along with the assembly. And you cannot unload an assembly except by tearing down the app domain. So, if your files are huge and you don't need them all of the time, loading them from separate files might be the preferrable option.
Sven Künzler
so how huge do you have in mind when you say large , lets say in cas e of xml file, is a file of 4kb huge ??? is there a practical way to test this?
Siddharth
4 KB is nothing nowadays ;-) Unless there are hundreds or thousands of those files, my choice in that case would be to put them in embedded resources.
Sven Künzler
A: 

Putting XML (blobs) in .resx

Positives:

  • Readily available

Negatives:

  • It would increase the memory load, if the content is big in size. Big-in-size is in comparison to assembly size without content. If an assembly size is 10kb and content size is 10kb, even though 10kb is not bigger in today's scenario, one can reduce assembly size to half just by keeping content in separate file.
  • Code manageability goes to down drastically, by keeping XML as string Key-value-pairs in RESX. As resx editor is not be XML sensitive.

If one is very keen keeping xml content as embedded resource, you can create XML file and keep it as file resource inside RESX.

nils_gate