in. NET, because a different node corresponds to a class to handle it. NET inside for convenience, has built up some classes for us to use, so that when we read the configuration file, we do not have to define the class to handle their own defined custom nodes.
below we have written a configuration file:
<?xml version= "1.0" encoding= "Utf-8"?><configuration> <configSections> <!-- Use ignoresection to handle custom 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 configuration file is written in front of the custom profile- </configSections> <mailserveraddress address= " Mail.tracefact.net "Username=" LHC "password=" 124324 "/> </configuration>
The node name is: Mailserveraddress, with three attributes, defined in section SingleTagSectionHandler to handle this node.
namespace custom 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 in the form of 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, after calling GetSection strong Hashtable, you can read the attribute value 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 the custom node.
The above is. net--use. Net built-in handlers to handle the contents of your custom node demo, and more about topic.alibabacloud.com (www.php.cn)!