Why another application settings XML class?
- Because INI files are so Win16.
- The registry is too big and you could really screw something up messing with
- XML seems to be the popular choice.
See Read and Write application parameters
in XML for better reasons.
This class should make it easy to read, write and delete application settings
to an XML file using the familiar registry key/value nomenclature (ex.
"MyApp\Appearance\Font\Face"). If it doesn't make it easy, um... I
didn't write it.
The CXMLSettings Class
To use the class, there are only 6 methods you will need to worry about.
void SetSettingsFile(CString cstrFile)
- Sets the path and filename for the XML settings file.
long GetSettingLong(CString cstrBaseKeyName, CString cstrValueName,
- Returns a long value extracted from the settings file given a key and value
long SetSettingLong(CString cstrBaseKeyName, CString cstrValueName,
- Sets a long value in the settings file given a key and value name.
CString GetSettingString(CString cstrBaseKeyName, CString
cstrValueName, CString cstrDefaultValue)
- Returns a string value extracted from the settings file given a key and
long SetSettingString(CString cstrBaseKeyName, CString cstrValueName,
- Sets a string value in the settings file given a key and value
BOOL DeleteSetting(CString cstrBaseKeyName, CString
- Deletes a key or value from the settings file given a key and value
Other methods in the class parse key/value "chains", and load, save, and
traverse the settings file.
How to Use It
SetSettingsFile to tell the class where the XML file will
- Call one of the Get, Set or Delete methods using the registry-like
nomenclature for the first parameter (ex. "MyApp\Appearance\Font"). A
default value may also be sent as the last parameter to the Get methods.
DeleteSetting method can be used to delete an entire key or
a value under a key.
If the XML file does not exist or if a key/value does not exist, the Set
methods will create it and the Get methods will return the default value.
The class and the demo app use MFC and MSXML 4.0. Please let me know if you find any bugs are would
like to see improvements.
Other articles lie this one: