Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted
Have you investigated System.XML? This namespace provides a number of classes to read/write and manipulate XML data.

Afraits

"The avalanche has started, it is too late for the pebbles to vote"

Posted

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

Posted
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

  • Administrators
Posted

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

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...