13.07.2015 Views

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Table 15-2: Predef<strong>in</strong>ed Section HandlersClassDictionarySectionHandlerIgnoreSectionHandlerNameValueFileSectionHandlerNameValueSectionHandlerS<strong>in</strong>gleTagSectionHandlerDescriptionReads name/value pairs and groups them<strong>in</strong> a hash table object.The System.Configuration classes ignorethe sections marked with this handlerbecause their contents will be processedby other components. This handler is analternative to us<strong>in</strong>g and declar<strong>in</strong>g customhandlers.Reads name/value pairs from a filereferenced <strong>in</strong> the sectionand groups them <strong>in</strong> aNameValueCollection object.Reads name/value pairs and groups them<strong>in</strong> a NameValueCollection object.Reads sett<strong>in</strong>gs from attributes stored <strong>in</strong> as<strong>in</strong>gle <strong>XML</strong> node. The data is returned asa hash table.In the .<strong>NET</strong> Framework, the classes <strong>in</strong> the System.Configuration namespace areresponsible <strong>for</strong> pars<strong>in</strong>g the contents of the configuration files. These classes aredesigned to process the entire contents of the configuration files. The classes alsothrow an exception when a configuration section lacks a correspond<strong>in</strong>g entry <strong>in</strong> the block and when the layout of the data does not match the declaration.Of the five section handlers, we have exam<strong>in</strong>ed NameValueSectionHandler andNameValueFileSectionHandler. The DictionarySectionHandler class is very similar; itdiffers only <strong>in</strong> that it stores sett<strong>in</strong>gs <strong>in</strong> a hash table <strong>in</strong>stead of <strong>in</strong> a NameValueCollectionobject. Collection objects are more efficient if they are used to store a small number ofitems (ideally fewer than 10), whereas a hash table provides better per<strong>for</strong>mance withlarge collections of items. The IgnoreSectionHandler and S<strong>in</strong>gleTagSectionHandlerclasses deserve a bit more attention, and we'll look at them next.The IgnoreSectionHandler Section HandlerA few subsystems <strong>in</strong> the .<strong>NET</strong> Framework store configuration data <strong>in</strong> themach<strong>in</strong>e.config file but process the data themselves, without rely<strong>in</strong>g on the servicesprovided by the System.Configuration classes. For example, the mach<strong>in</strong>e.config fileconta<strong>in</strong>s remot<strong>in</strong>g and startup <strong>in</strong><strong>for</strong>mation that is processed outside the configurationeng<strong>in</strong>e. To prevent the configuration file from pars<strong>in</strong>g exceptions, you can use a dummysection handler—IgnoreSectionHandler. This handler handles sections of configurationdata rather than rely<strong>in</strong>g on the classes <strong>in</strong> System.Configuration. It could be argued thatsuch data should be stored <strong>in</strong> a system configuration file, like the mach<strong>in</strong>e.config file, or<strong>in</strong> a custom file. Look<strong>in</strong>g at the follow<strong>in</strong>g excerpt from the mach<strong>in</strong>e.config file, you cansee that remot<strong>in</strong>g configuration sett<strong>in</strong>gs are processed by the remot<strong>in</strong>g classes,whereas HTTP run-time configuration sett<strong>in</strong>gs are processed by a custom handler:518

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!