The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Config::DotNetXML::Parser - Parse a .NET XML .config file

SYNOPSIS

use Config::DotNetXML::Parser;

my $parser = Config::DotNetXML::Parser->new(File => $file);

my $config = $parser->data();

DESCRIPTION

This module implements the parsing for Config::DotNetXML it is designed to be used by that module but can be used on its own if the import feature is not required.

The configuration files are XML documents like:

   <configuration>
      <appSettings>
          <add key="msg" value="Bar" />
      </appSettings>
   </configuration>

and the configuration is returned as a hash reference of the <add /> elements with the key and value attributes providing respectively the key and value to the hash. 'appSettings' is the default section and is the one that is exported into your namepace if you asked Config::DotNetXML to do so.

Named sections can also be introduced:

   <configuration>
     <configSections>
        <section name="CustomSection" />
     </configSections>

     <CustomSection>
       <add key="msg" value="Bar" />
     </myCustomSection>
   </configuration>

And the items in the named section can be accessed via the getConfigSection() method. Custom sections can appear in the same file as the appSettings default. It should be noted that single value sections and custom section handlers are currently not supported.

METHODS

new

Returns a new Config::DotNetXML::Parser object - it takes parameters in key => value pairs:

File

The filename containing the configuration. If this is supplied then the configuration will be available via the data() method immediately, otherwise at the minimum parse() will need to be called first.

parser

Convenience accessor/mutator for the underlying XML parser.

parse

This causes the configuration file to be parsed, after which the configuration will be available via the data() method. It can be supplied with an optional filename which will remove the need to use the File() method previously.

data

Returns parsed data from the default (appSettings) section - this will be undefined if parse() has not previously been called or there is no appSettings section in the configuration.

getConfigSection

Returns the named configuration section or a false value if there is no such section.

configData

Accessor/Mutator for the underlying parsed configuration data, you will almost certainly be accessing the configuration through the methods of Config::DotNetXML rather than using this directly.

File

Returns or sets the name of the file to be parsed for the configuration.

BUGS

Those familiar with the .NET Framework will realise that this is not a complete implementation of all of the facilities offered by the System.Configuration class: specifically custom section handlers, and single value sections - these should come later.

The observant will have noticed that the use of configuration sections causes the file not to be strictly valid XML inasmuch as the schema cannot be defined prior to parsing - this is unfortunately the way that the .NET framework has it specified, the named sections should probably be dealt with using a 'name' attribute instead.

AUTHOR

Jonathan Stowe <jns@gellyfish.co.uk>

COPYRIGHT

This library is free software - it comes with no warranty whatsoever.

Copyright (c) 2004, 2005, 2016 Jonathan Stowe

This module can be distributed under the same terms as Perl itself.