How to add a xml in web.config?

前端 未结 3 1257
暖寄归人
暖寄归人 2021-01-13 06:52

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 w

3条回答
  •  广开言路
    2021-01-13 07:16

    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:

    
        
          
    ... ... complex XML ... ...

    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 ...
    

提交回复
热议问题