In. Net. Because of the different nodes, the corresponding class to deal with it,. NET inside for convenience. We have built in some classes for our use. Allows us to read the configuration file. You do not have to define your own classes to handle your own defined nodes.
Below we have written a configuration file:
<?xml version= "1.0" encoding= "Utf-8"?><configuration> <configSections> <!-- Use Ignoresection to process your own defined nodes- <!--<section name= "mailserveraddress" type= " System.Configuration.IgnoreSection, System.Configuration, version=4.0.0.0, Culture=neutral, publickeytoken= B03F5F7F11D50A3A "allowlocation=" false "restartonexternalchanges=" true "/>--> <section name=" Mailserveraddress "type=" System.Configuration.SingleTagSectionHandler "/> <!--Note that Specifies that the handler's configuration file is written in front of its own definition profile- </configSections> <mailserveraddress address= " Mail.tracefact.net "Username=" LHC "password=" 124324 "/> </configuration>
The node name is: Mailserveraddress. There are three attributes that define the SingleTagSectionHandler in the section to handle this node.
namespace self-defined node and built-in handler { class program { static void Main (string[] args) { Examplesingletagsectionhandler (); } private static void Examplesingletagsectionhandler () { //singletagsectionhandler returns all the properties of a node as Hashtable Hashtable mailserver = (Hashtable) configurationmanager.getsection ("mailserveraddress");// Calling GetSection returns a hashtable string address = mailserver["Address". ToString (); String username = mailserver["username"]. ToString (); String PassWord = mailserver["PassWord"]. ToString (); Console.WriteLine (address+ "----" +username+ "------" +password);}}}
After the configuration file is written, the GetSection Hashtable can be called to read the attribute values of the node in the form of Key--value.
In. NET, in addition to this type in the example above, we can also use other built-in type to handle our own defined nodes.
. net--using. Net built-in handlers to handle their own defined nodes demo