SO #25456238

CSharp · Console

/Program.cs

using System;
using System.Xml;
using System.Xml.Serialization;
using System.Collections.Generic;
using System.IO;
using System.Text;
					
public class Program
{
	public static void Main()
	{
		string xml = "<items><item><version>1.0</version><title>Example</title><changelog>http://example.com/changelog.txt</changelog><url>http://www.example.com/download/</url></item></items>";
		
		XmlSerializer serializer = new XmlSerializer(typeof(UpdateXML));
		
		UpdateXML updateXml = null;
		using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(xml)))
		using (var reader = new XmlTextReader(stream))
		{
			updateXml = (UpdateXML)serializer.Deserialize(reader);
		}
		
		Console.WriteLine("Deserialized {0} item(s)", updateXml.Items.Count);
	}
}

[XmlRootAttribute("items")]
public class UpdateXML
{
    public class Item
    {
        private string _versionString;
        private string _title;
        private string _changelog;
        private string _url;

        [XmlElement("version")]
        public string VersionString
        {
            get { return this._versionString; }
            set { this._versionString = value; }
        }

        public Version Version
        {
            get 
            {
                if (string.IsNullOrEmpty(this._versionString))
                    return null;

                return new Version(this._versionString); 
            }
        }

        [XmlElement("title")]
        public string Title
        {
            get { return this._title; }
            set { this._title = value; }
        }

        [XmlElement("changelog")]
        public string ChangeLog
        {
            get { return this._changelog; }
            set { this._changelog = value; }
        }

        [XmlElement("url")]
        public string URL
        {
            get { return this._url; }
            set { this._url = value; }
        }
    }

    private List<Item> _items;

	[XmlElement("item")]
    public List<Item> Items
    {
        get { return this._items; }
        set { this._items = value; }
    }

    public UpdateXML()
    {

    }
}
;