What's your favorite way to read XML files?
Let's take this xml structure as an example:
<?xml version="1.0" encoding="utf-8"?>
<Configuration-content>
<XFile Name="file name 1" />
<XFile Name="name2" />
<XFile Name="name3" />
<XFile Name="name4" />
</Configuration-content>
C # interface for implementation:
public class Configuration
{
public XFile[] Files { get; set; }
}
public interface IConfigurationRipository
{
Configuration Get();
void Save(Configuration entity);
}
I wonder what is the best way to do this.
The challenge is to implement IConfigurationRipository
using your favorite approach.
+2
a source to share
3 answers
Is there a reason not to use XML Serialization ?
using (Stream myStream = new FileStream(fileName, FileMode.Open))
{
XmlSerializer xs = new XmlSerializer(typeof(XConfiguration));
XConfiguration config = xs.Deserialize(myStream) as XConfiguration;
}
0
a source to share
The easiest way for this simple XML format is to use a DataSet object (.readXML ()). Here is a simple example application that does this - and displays the contents of the DataSet in a tree / grid format: http://www.dot-dash-dot.com/files/WTFXMLSetup_1_8_0.msi . Here is the source for this program: http://www.dot-dash-dot.com/files/wtfxml.zip .
0
a source to share