I'm trying to decide on the best way to load in some configuration settings. Basically, I have an application that several people will log into, and once they've logged in, I want to load all of their settings (for example: colors, font sizes, personal records, etc.)
I was thinking of using an XML file to do this because I thought it would be fairly easy to parse in .NET, but it seems to be more difficult that I anticipated.
<ProgramSettings>
<database file="C:\database.mdb" />
</ProgramSettings>
<UserSettings>
<user key="user1">
<layout color="red" fontsize="5" />
<data file="C:\test1.txt" />
</user>
<user key="user2">
<layout color="blue" fontsize="2" />
<data file="C:\test2.txt" />
</user>
</UserSettings>
Note: For some reason some of the code is not appearing, but basically there are major sections labeled "ProgramSettings" and "UserSettings." Edit: Thanks whoever fixed that for me.
Anyway, what I would like to do is get the "user key" which will be the user's login name or something. Then, it would be nice to be able to do something like this:
String userLogin = "user1";
// returns red
String color = myXMLFile["UserSettings"][userLogin]["layout"]["color"];
// returns 5
String fontSize = myXMLFile["UserSettings"][userLogin]["layout"]["fontsize"];
Is anything like this possible? All the research I've done seems to indicate that you need to loop through each value. I'd like to load the whole file, and access any element directly.
It would also be cool if you could edit the values like:
myXMLFile["UserSettings"][userLogin]["layout"]["fontsize"] = "green";