How to use C# nested structures to access tree of data

Posted by zotty on Stack Overflow See other posts from Stack Overflow or by zotty
Published on 2010-03-12T15:39:50Z Indexed on 2010/03/12 17:57 UTC
Read the original article Hit count: 182

Filed under:
|

I'm importing some XML to C#, and want to be able to access data from the XML in the form of what I think is a nested structure. (I may be wrong!)

What I have in my XML is in the following form:

<hardwareSettings initial="true>
    <cameraSettings width="1024" height="768" depth="8" />
    <tiltSettings theta="35" rho="90">
</hardwareSettings>

I can import each setting alright, so I have them all in individual ints, but I would like to be able to access it in the form

int x=hardwaresettings.camerasettings.width;
int rho=hardwaresettings.tiltsettings.rho;

I've tried various arrangements of structs within structs, but I don't seem able to cast a new object (hardwaresettings) that contains the appropriate children (camerasettings.width & tiltsettings.rho).

Sorry if I'm not using the right lingo... I'm reading myself in circles here!

© Stack Overflow or respective owner

Related posts about c#

Related posts about data-structures