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.

snapshot of the row as it was orig<strong>in</strong>ally read, and the second node conta<strong>in</strong>s the currentvalues. The DiffGram represents a snapshot of the DataSet state and contents at agiven moment. To write DiffGrams, ADO.<strong>NET</strong> uses an XmlWriter object.The <strong>in</strong>tegration of and <strong>in</strong>teraction between <strong>XML</strong> and ADO.<strong>NET</strong> classes is discussed <strong>in</strong>Chapter 8.Application ConfigurationBe<strong>for</strong>e <strong>Microsoft</strong> W<strong>in</strong>dows 95, applications stored configuration sett<strong>in</strong>gs to a text filewith a .<strong>in</strong>i extension. INI files store <strong>in</strong><strong>for</strong>mation us<strong>in</strong>g name/value pairs grouped undersections. Ultimately, an INI file is a collection of sections, with each section consist<strong>in</strong>g ofany number of name/value pairs.W<strong>in</strong>dows 95 revamped the role of the system registry—a centralized data repositoryorig<strong>in</strong>ally <strong>in</strong>troduced with W<strong>in</strong>dows NT. The registry is a collection of b<strong>in</strong>ary files that theoperat<strong>in</strong>g system manages <strong>in</strong> exclusive mode. Client applications can read and writethe contents of the registry only by us<strong>in</strong>g a tailor-made API. The registry works as ak<strong>in</strong>d of hierarchical database consist<strong>in</strong>g of root nodes (also known as hives), nodes,and entries. Each entry is a name/ value pair.All system, component, and application sett<strong>in</strong>gs are supposed to be stored <strong>in</strong> theregistry. The registry cont<strong>in</strong>ues to <strong>in</strong>crease <strong>in</strong> size, contribut<strong>in</strong>g to the creation of aconfiguration subsystem with a s<strong>in</strong>gle (and critical) po<strong>in</strong>t of failure. More recently,applications have been encouraged to store custom sett<strong>in</strong>gs and preferences <strong>in</strong> a localfile stored <strong>in</strong> the application's root folder. For .<strong>NET</strong> Framework applications, thisconfiguration file is an <strong>XML</strong> file written accord<strong>in</strong>g to a specific schema.In addition, the .<strong>NET</strong> Framework provides a specialized set of classes to read and writesett<strong>in</strong>gs. The key class is named AppSett<strong>in</strong>gsReader and works as a k<strong>in</strong>d of parser <strong>for</strong>a small fragment of <strong>XML</strong> code—mostly a node or two with a few attributes.ASP.<strong>NET</strong> applications store configuration sett<strong>in</strong>gs <strong>in</strong> a file named web.config that islocated <strong>in</strong> the root of the application's virtual folder. W<strong>in</strong>dows Forms applications, onthe other hand, store their preferences <strong>in</strong> a file with the same name as the executableplus a .config extension—<strong>for</strong> example, myprogram.exe.config. The CONFIG file mustbe available <strong>in</strong> the same folder as the ma<strong>in</strong> executable. The schema of the CONFIG fileis the same regardless of the application model.The contents of a CONFIG file is logically articulated <strong>in</strong>to sections. The .<strong>NET</strong>Framework provides a number of predef<strong>in</strong>ed sections to accommodate Web andW<strong>in</strong>dows Forms sett<strong>in</strong>gs, remot<strong>in</strong>g parameters, and ASP.<strong>NET</strong> run-time characteristicssuch as the authentication scheme and registered HTTP handlers and modules.User-def<strong>in</strong>ed applications can extend the <strong>XML</strong> schema of the CONFIG file by def<strong>in</strong><strong>in</strong>gcustom sections with custom elements. By default, however, the AppSett<strong>in</strong>gsReaderclass supports only sett<strong>in</strong>gs expressed <strong>in</strong> a few <strong>for</strong>mats, such as name/value pairs anda s<strong>in</strong>gle tag with as many attributes as needed. This schema fits the bill <strong>in</strong> most cases,but when you have complex structured <strong>in</strong><strong>for</strong>mation, it soon becomes <strong>in</strong>sufficient.In<strong>for</strong>mation is read from a section us<strong>in</strong>g special objects called section handlers. If nopredef<strong>in</strong>ed section structure fits your needs, you can provide a tailor-madeconfiguration section handler to read your own <strong>XML</strong> data, as shown here:10

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

Saved successfully!

Ooh no, something went wrong!