开发者

.Net application configuration add xml-data

I need to add xml-content to my application configuration file. Is there a way to add it directly to the appSettings section or do I need to 开发者_开发问答implement a configSection?

Is it possible to add the xml to a CDATA element?


I don't think you can store the xml in the config file without implementing each of it's branches as ConfigurationElement.

You can store the full xml as CDATA though. I think this will help you in the implementation: http://devpinoy.org/blogs/jakelite/archive/2009/03/22/how-to-add-cdata-or-text-in-a-configurationelement.aspx


If it goes beyond standard key value pairs you'll have to create your custom section. If it is xml I don't see why you would want to store it as a CDATA blob.

Custom config sections are pretty straightforward to setup - have a look at the accepted answer on this question which covers the topic in detail.


You can (and I have) save XML in a configuration file as a string. It'll look like this:

<setting name="MyXml" serializeAs="String">
    <value>&lt;foo&gt;Here's my XML.  Read it and weep.&lt;/foo&gt;</value>
</setting>

To retrieve it, you'd do:

string xml = Properties.Settings.Default.MyXml;
XmlDocument d = new XmlDocument();
d.LoadXml(xml);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜