kejpa Posted March 4, 2005 Posted March 4, 2005 Hi, I trying to make a flexible config file using XML, but I'm not sure how I should read it... This is the way it looks: <Settings> <ComPorts> <IO1> <PortName>COM2</PortName> <BaudRate>19200</BaudRate> </IO1> <IO2> <PortName>COM4</PortName> <BaudRate>4800</BaudRate> </IO2> </ComPorts> </Settings> There can be any (up to 10) number of IO:s and for each IO I need to create a SerialPort. My Q is how I read a file with unknown number of IO:s? Should I add an element that contains the number of IO:s? XML is supposed to be so simple and flexible. I only find it confusing, what have I missed?!? :( TIA /Kejpa Quote
Afraits Posted March 4, 2005 Posted March 4, 2005 Have you investigated System.XML? This namespace provides a number of classes to read/write and manipulate XML data. Quote Afraits "The avalanche has started, it is too late for the pebbles to vote"
kejpa Posted March 4, 2005 Author Posted March 4, 2005 Yes, I have had a look at it and it's messy. And I get the feeling that in .NET2005 (which I use) it's even more complex. There are too many almost the same classes and you get no help in choosing. As for the time being I've decided that there can only be two IO:s (no more, no less)but I know my manager won't like that limitation. Regards /Kejpa Quote
Administrators PlausiblyDamp Posted March 4, 2005 Administrators Posted March 4, 2005 Why not create a schema that allows multiple IO elements? COM2 19200 COM4 4800 If you are having problems with a particular piece of code or way of dealing with the XML post it here and see if you can get more specific help. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
kejpa Posted March 4, 2005 Author Posted March 4, 2005 Why not create a schema that allows multiple IO elements? The schema you suggested will be just fine, still there's the question of how to read it in a flexible manner?!?! What if I have an old settings file w/o some of the new sections (eg. "Parameters")? As of my current implementation that generates an error. If you are having problems with a particular piece of code or way of dealing with the XML post it here and see if you can get more specific help. Yes, dealing with XML is a problem to me. It's not as flexible as I find using Registry keys or ini files, but I've realized that I have to abandon my prejudices about this "thingy" that I rejected as a hype back in '98 Regards /Kejpa Quote
Administrators PlausiblyDamp Posted March 4, 2005 Administrators Posted March 4, 2005 Attached a simple project to show how you can use .Net's built in XML serialisation support to handle reading the file structure I posted above. Just step through the code and keep your eye on the contents of the variable s just before the End Sub statement.WindowsApplication6.zip Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
kejpa Posted March 7, 2005 Author Posted March 7, 2005 Thanx! I'll have a look at it at once! /Kejpa Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.