- Use my answer here to create a C# class that represent your XML.
- Use the
XmlSerializer
to deserialize the contents of the XML file.
- Do whatever you want to do with the deserialized stuff.
Here are the classes step 1 will generate for you:
/// <remarks/>
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
public partial class AppList
{
private AppListVLC[] vLCField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("VLC")]
public AppListVLC[] VLC
{
get
{
return this.vLCField;
}
set
{
this.vLCField = value;
}
}
}
/// <remarks/>
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class AppListVLC
{
private string pathField;
private string mD5GoldenHashField;
/// <remarks/>
public string Path
{
get
{
return this.pathField;
}
set
{
this.pathField = value;
}
}
/// <remarks/>
public string MD5GoldenHash
{
get
{
return this.mD5GoldenHashField;
}
set
{
this.mD5GoldenHashField = value;
}
}
}
And here is how to serialize and deserialize:
public static void Main()
{
var serializer = new XmlSerializer(typeof(AppList));
var reader = new StreamReader("YourFile.xml");
var result = serializer.Deserialize(reader) as AppList;
reader.Close();
foreach (var thisVlc in result.VLC)
{
Console.WriteLine(thisVlc.MD5GoldenHash);
}
// if you want to make changes to xml file then do the following
result.VLC[0].MD5GoldenHash = "Something to show modificaition";
serializer.Serialize(new StreamWriter("YourFileOrSomeOtherFile.xml"), result);
}