Chapter 2 Migrating from Another File Format
2.1 Introduction: Description of Problem
Consider the following scenario. Your company has been selling an application for the past five years and, up until now, that application has used, say, an XML file to store its configuration information. You are designing an updated version of the application, and you would like to switch from using XML to Config4* for its configuration file. There is just one problem: you need to find a way for users to be able to automatically convert their existing XML-based configuration data into Config4* format. How can you achieve this goal?
An easy way to help users migrate from, say, an XML file format to Config4* is to write a program that does the following:
- Call Configuration.create() to create an empty configuration object.
- Parse an input XML file and store the result in a DOM tree.
- Traverse the DOM tree and, for each name-value pair you encounter, call cfg.insertString() or cfg.insertList() to add the name-value pair into the configuration object.
- When you have finished traversing the DOM tree, call cfg.dump() to get a textual representation of all the configuration information, and write this to a configuration file.
That’s all that is required.