Quantcast
Viewing latest article 1
Browse Latest Browse All 3

Answer by Justin Niessner for Serialize class to XML?

If both of your classes were tagged with the [Serializable] attribute, then saving things to a file should be as simple as:

var serializer = new XmlSerializer(typeof(Transport));using(var writer = new StreamWriter("C:\\Path\\To\\File.xml")){    serializer.Serialize(writer, instance);}

Update

Sorry, didn't realize you were asking about how to customize the output. That is what the [XmlAttribute] and [XmlElement] attributes are for:

public class Transport{    // Store TransportType as an attrribute called Type in the XML    [XmlAttribute("Type")]    public string TransportType { get; set; }    // Rest of Implementation}

Viewing latest article 1
Browse Latest Browse All 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>