Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I store an XML value in my .NET App.Config file

I am trying to store an xml value in my app.config file. The app.config does not like this and I cannot use the <![CDATA[ construct to ignore the XML'ness of my value.

Is there a way to do it?

Value example:<FieldRef Name='LinkfileName' Nullable='True'/><FieldRef Name='Web' Nullable='True'/>

like image 633
Nat Avatar asked Oct 05 '08 20:10

Nat


People also ask

Why config files are XML?

The primary motivation for using XML-based configuration is to be able to configure different instances of the same object in different ways. For example, with a single XML configuration file, you can specify different options for different applications.


1 Answers

You can save an XML document as text in an attribute value if you escape the character entities:

&lt;FieldRef Name=&quot;Linkfilename&quot; ...

You can then use XmlDocument.Load() to parse the text value.

Note that this won't work for your example because your value is an XML document fragment and not a well-formed XML document. You either need to wrap it in an enclosing document element (whose markup will still be escaped) or use a properly-initialized XmlReader to process the value once you've retrieved it from the configuration.

like image 114
Robert Rossney Avatar answered Nov 13 '22 10:11

Robert Rossney