using System;
using System.Xml.Serialization;
[XmlRoot("cell-phone")]
public class CellPhone {
public CellPhone () {
}
[XmlAttribute("name")]
public string Name {
get {return this._name;}
set {this._name = value;}
}
[XmlAttribute("year")]
public int Year {
get {return this._year;}
set {this._year = value;}
}
[XmlElement("description")]
public string Description {
get {return this._description;}
set {this._description = value;}
}
private string _name = "";
private int _year = 2000;
private string _description = "";
}
class XMLSerializationSample {
static void Main(string[] args) {
XmlSerializer serializer = new XmlSerializer(Type.GetType("CellPhone"));
CellPhone cellPhone = new CellPhone();
cellPhone.Description = "Some description";
cellPhone.Name = "AAA";
serializer.Serialize(Console.Out, cellPhone);
}
}
|