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

大城市里の小女人 提交于 2019-12-07 03:57:31

问题


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'/>


回答1:


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.



来源:https://stackoverflow.com/questions/172646/how-do-i-store-an-xml-value-in-my-net-app-config-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!