I'm looking for a good clean way of writing XML to a configuration file and being able to read it back into the Application.
I have an Array of properties that each contain a list of fields.
For example a list of Camera Properties.
Each property has Name, Value, Category, Type, Description.
I would like my XML Config to look like this
<Camera_Properties>
<Property Name="Height" Value="40" Category="Dimensions" Type="Int" Description="The height of the box">
<Property Name="Width" Value="40" Category="Dimensions" Type="Int" Description="The width of the box">
</Camera_Properties>
Firstly is this possible, or practical?
I Can't seem to find a way of writing this and more impotently being able to parse it in such a way that it can be pulled apart so I could read the Config file and as each element is found call code like this
SetProperty(xmlelement.name, xmlelement.Value, xmlelement.Type);
So far i have managed to get this output
<Camera_Properties>
<Property>
<Name> Height</Name>
<Value> 100 </Value>
<Category> Dimensions </Category>
<Type> Int </Type>
<Description> Height of the box </Description>
</Property>
</Camera_Properties>
But this is not practical for how i need to use the configuration file.
I have used System.Xml.XmlDocument to get this far. If there is a better alternative i would appreciate suggestions.
But as there are hundreds of properties this is too messy and hard to read.
If anyone can help or knows where there may be a relevant example i could use as a guide it would greatly help.
Thanks
EDIT
I would like to loop through and generate an XML file with these properties from an array. The idea is that this file can be used to load in proprieties and set properties as the change each time the hardware is powered off.
public void CreateXML()
{
// Setup document and header tags
foreach(Property prop in propertyArray)
{
create single element here with prop.Name, Prop.Age etc as attributes
}
SaveXml(Filename);
}
The SDK i use for the hardware has an Array of parameters so i would prefer to generate the file from this instead of a dataset.