|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Merging two configuration filesI've two different configuration files with the same structure. One of them is the default setting, which gets downloaded from the server, and the other one is the user settings. The user settings overwrite the default settings. Similar to what .Net does with the machine.config file and the web.config. Now I need to merge these two files to get the actual settings. The default settings file: <bookmarks> <add name="b1" lat="1" long="1"/> <add name="b2" lat="1" long="1"/> <add name="b3" lat="1" long="1"/> <bookmarks/> The user settings file: <bookmarks> <remove name="b1" lat="1" long="1"/> <add name="b4" lat="1" long="1"/> <bookmarks/> The result after merging these two files should be: <bookmarks> <add name="b2" lat="1" long="1"/> <add name="b3" lat="1" long="1"/> <add name="b4" lat="1" long="1"/> <bookmarks/> Any ideas how to do this? If you think I should post this message to another group let me know? Thanks Houda Hi Houda,
> The user settings overwrite There's nothing automatic in .NET for this, so your best bet is to first > the default settings. Similar to what .Net does with the > machine.config file and the web.config. Now I need to merge these two > files to get the actual settings. read the default settings into memory (into some kind of collection object perhaps), and then read the user settings. If you use the "name" attribute as a key, then for each line you load from the user's settings, check to see if a setting with a similar name already exists in your collection, and then act accordingly. In the end, you have effectively merged the two XML files. Then, you can process the collection's data or write the data out as a new XML file, if that is what you want to do. Hope this helps. -- Regards, Mr. Jani Järvinen C# MVP Helsinki, Finland ja***@removethis.dystopia.fi http://www.saunalahti.fi/janij/ It seems there is a way to do this. Take a look at this one:
http://72.14.253.104/search?q=cache:RqMrrtmqM_0J:https://forums.microsoft.com/MSDN/ShowPost.aspx%3FPostID%3D671699%26SiteID%3D1+ExeConfigurationFileMap+MachineConfigFilename+merging&hl=en&ct=clnk&cd=5&gl=us Houda |
|||||||||||||||||||||||