stacker
stacker

Reputation: 14931

What is your favorite way to read XML files?

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.

Upvotes: 2

Views: 246

Answers (3)

Ron Savage
Ron Savage

Reputation: 11079

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.

Upvotes: 0

Ian Mercer
Ian Mercer

Reputation: 39277

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

Upvotes: 1

Randy Levy
Randy Levy

Reputation: 22655

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;
}

Upvotes: 0

Related Questions