如何添加XML web.config中? [英] How to add a xml in web.config?

查看:143
本文介绍了如何添加XML web.config中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于应用程序配置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 ...

这篇关于如何添加XML web.config中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆