views:

58

answers:

2

I know that app config is used to provide environmental type of values for process variables. And it is very much key/value oriented.

But I have a process (windows service) that uses a skeleton xml template file to produce a fuller version of that file after processesing.

What about the idea of including that 'skeleton xml' in the app config file?

I am trying to aviod having a standalone xml skeleton file, since it is 'configuration' related, in a way.

A: 

Well, you can

  • To create a custom configuration section into .config file and work with its serialized version
  • To store that XML directly at appSettings, encoded as string
  • To define a file path at appSettings and, there, place your XML file

If you ask me, I would go with last option, since it's easier to maintain.

Rubens Farias
The 3rd option then being the standalone XML file, located via the app config file?
Chris
Yes Chris; that's easier to update and doesn't requires an app pool recycle
Rubens Farias
+1  A: 

It's straightforward to store XML in an application configuration setting if you've serialized it as XML text, e.g. to save it, assuming that myXmlDocument is an XmlDocument:

Properties.Settings.Default.MyXmlSkeleton = myXmlDocument.OuterXml;

and to retrieve it:

myXmlDocument.LoadXml(Properties.Settings.Default.MyXmlSkeleton);

But you won't readily to be able to change the XML by editing the configuration file, since it will be stored as XML text, e.g.:

value='<MyXmlDocument/>'

That's probably not a problem, because you're probably not going to want to edit the application configuration file to change the XML anyway - there's far too much risk of introducing well-formedness errors if you do that.

Generally, though, I find that this isn't the right approach; I'll either load the XML from the file system at runtime and store the path to the XML document in the configuration file, or I'll include the XML as a string resource.

Robert Rossney