For configuration file trade-offs,. config VS. xml,. config. xml

Source: Internet
Author: User
Tags connectionstrings

For configuration file trade-offs,. config VS. xml,. config. xml

As we all know, some of the flexibility of the program is "configuration.

 

Of course, the config file has never been easy for. NET users. At least, I think it is very troublesome.

 

1. config

. NET configuration file is convenient, in fact, the most convenient is the deleettings

<appSettings>    <add key="apiKey" value = "8asdf9as9d2asd" /></appSettings>

User-Defined configuration is cumbersome. You must be familiar with the. NET configuration file system to understand it.

Of course, the people who are dedicated provide a DSL masterpiece-ConfigurationSectionDesigner.

To some extent, my custom configuration for. NET is contradictory:

I like it because it is strict and cannot be modified;

I don't like it. It is troublesome to modify the design, so I need to make a lot of references.

 

2. XML

XML is very flexible, but I am afraid of its complicated APIs. I have been holding this attitude until I used the Linq To Xml.

I even want to write an XMLHelper multiple times. It's silly to see a bunch of definitions and APIs each time.

Here, I changed my attitude towards Xml with the help of Linq To XML.

Main APIs:

1) load a document;

XDocument doc = XDocument. Load (path); or XElement doc = XElement. Load (path );

The difference is that after XElement is loaded, XDocument is treated as an element, while XDocument has a typical attribute-Root.

2) Search for elements;

It provides a good tree-like API that gives people a clear feeling.

Doc. elements ("yourName"); // search for the Element Set doc. element ("yourName"); // find a single Element doc. descendants ("yourName"); // search for child element

Of course, it is natural to add the extension of Linq, Where, Select, and other Lambda methods.

3) modify, add, and delete elements;

SetValue, Add, AddAfterSelf, AddBeforeSelf

RemoveAll

XElement root = new XElement("Categories",        new XElement("Category",            new XAttribute("CategoryID", "1"),            new XElement("CategoryName", "Beverages"),            new XElement("Description", "Soft drinks, coffees, teas, beers, and ales")        )    );    root.Element("Category").Add(new XAttribute("AddDate", DateTime.Now.ToShortDateString()));    root.Save(path);

 

It is so convenient to read and write xml files.

3. Select

In general, XML is more flexible than the config file.

I tend to use XML for configuration when config cannot cope with various complex configurations (code modification is helpless;

When the configuration is fixed, I prefer to use config for configuration.

When using an XML file, there is a VS prompt-select the XML file, right-click the file, properties, output directory, and select "always copy ".


C # how to change the XML file ending with config

App. the config file is the Configuration file of the application. operating on this file does not follow the normal XML file, but requires the class library Configuration provided by C # for operating the Configuration file. in addition, you must add this application (System. configuration): Right-click the solution in the file list on the Right of vs, select Add reference, and select System in the pop-up dialog box. add Configuration. it is troublesome to modify the configuration file. the following code can help you with Configuration config = ConfigurationManager. openExeConfiguration ("D :\\ yeyun \ MyQQ \ app. config ");
AppSettingsSection paietting = (AppSettingsSection) config. GetSection ("appSettings ");
If (deleetting. Settings ["key"] = null)
{
Deleetting. Settings. Add ("key", "net. tcp: // 192.168.1.101: 1234 ");
}
Else
{
Deleetting. Settings ["key"]. Value = "hao ";
}
ConnectionStringsSection conns = (ConnectionStringsSection) config. GetSection ("connectionStrings ");
If (conns. ConnectionStrings ["name"] = null)
{
ConnectionStringSettings conn = new ConnectionStringSettings ("name", "dddd ");
Conns. ConnectionStrings. Add (conn );
}
Config. Save ();

Modify the deleettings node and the connectionStrings node respectively.
However, I did not find the system. serviceModel node. I used vs2005. I don't know what version you are using
Note: This configuration file is not recommended to be modified when the program is running...

Where is the configuration file description of the webxml file and the strutsconfig file in struts-129-bin?

All in the struts-blank.war
Decompress the package with winrarto obtain an empty web project application.
All the documents here are empty.
Includes the web. xml and struts-config.xml you need
If you cannot find the struts package, it may be because some packages contain the source code. I didn't know it at the beginning. I downloaded a struts1.2.7 package on the apache website, which is the source code.
As for your processing ing Applications
I don't understand either.




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.