Reading XML file

kejpa

Well-known member
Joined
Oct 10, 2003
Messages
320
Hi,
I trying to make a flexible config file using XML, but Im not sure how I should read it...
This is the way it looks:
PHP:
<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
 
Yes, I have had a look at it and its messy. And I get the feeling that in .NET2005 (which I use) its even more complex.
There are too many almost the same classes and you get no help in choosing.

As for the time being Ive decided that there can only be two IO:s (no more, no less)but I know my manager wont like that limitation.

Regards
/Kejpa
 
Why not create a schema that allows multiple IO elements?
Code:
<Settings>
    <ComPorts>
        <IO id="1">
            <PortName>COM2</PortName>
            <BaudRate>19200</BaudRate>
        </IO>
        <IO id="3">
            <PortName>COM4</PortName>
            <BaudRate>4800</BaudRate>
        </IO>
    </ComPorts>
</Settings>
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.
 
PlausiblyDamp said:
Why not create a schema that allows multiple IO elements?
The schema you suggested will be just fine, still theres 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.

PlausiblyDamp said:
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. Its not as flexible as I find using Registry keys or ini files, but Ive realized that I have to abandon my prejudices about this "thingy" that I rejected as a hype back in 98

Regards
/Kejpa
 
Attached a simple project to show how you can use .Nets 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.
 

Attachments

Back
Top