views:

135

answers:

3

Let's take this xml structure as 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 to implement:

public class Configuration
{
    public XFile[] Files { get; set; }
}

public interface IConfigurationRipository
{
    Configuration Get();
    void Save(Configuration entity);
}

I wonder what's the best way to do that.

The task is to implement IConfigurationRipository using your favorite approach.

A: 

Is there any 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;
}
Tuzo
Why use this if we have LinqToXml?
stacker
@Tuzo: No bug fixes are being made to XML Serialization, and it's quite limited.
John Saunders
+1  A: 

DataContractSerializer > LinqToXml > XAML Serialization > XML Serializer >> String manipulation >> RegEx

Hightechrider
Is it mean that DataContractSerializer your best? if so, please implement this using it.
stacker
XAML serialization solution can be very interesting! but I don't sure it's good also to write.
stacker
A: 

Easiest way for that simple XML format is to use a DataSet object (.readXML()). Here is a simple example app that does that - and displays the DataSet contents in a tree/grid format: http://www.dot-dash-dot.com/files/WTFXMLSetup_1_8_0.msi. Here is the source for that program: http://www.dot-dash-dot.com/files/wtfxml.zip.

Ron Savage