由网友(爱生活爱健哥。)分享简介:我有一个用于应用程序配置XML格式的一些复杂的数据。我想保持在web.config中这个XML字符串。是否有可能增加一个大的XML字符串在web.config中,让它在code无处不在?I have some complex data which is used for application configurati...
我有一个用于应用程序配置XML格式的一些复杂的数据。我想保持在web.config中这个XML字符串。是否有可能增加一个大的XML字符串在web.config中,让它在code无处不在?
I have some complex data which is used for application configuration in xml format. I want to keep this xml string in web.config. Is it possible to add a big xml string in web.config and get it in code everywhere?
推荐答案
如果你不想写一个配置节处理程序,你可以只是把你的XML映射到 IgnoreSectionHandler :
If you don't want to write a configuration section handler, you could just put your XML in a custom configuration section that is mapped to IgnoreSectionHandler
:
<configuration>
<section
name="myCustomElement"
type="System.Configuration.IgnoreSectionHandler"
allowLocation="false" />
...
<myCustomElement>
... complex XML ...
</myCustomElement>
...
</configuration>
您就可以使用任何XML API读它,例如的XmlDocument
,的XDocument
,的XmlReader
类。例如:
You can then read it using any XML API, e.g. XmlDocument
, XDocument
, XmlReader
classes. E.g.:
XmlDocument doc = new XmlDocument();
doc.Load(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
XmlElement node = doc.SelectSingleNode("/configuration/myCustomElement") as XmlElement;
... etc ...
相关推荐
最新文章