Sunday, October 26, 2014

XML Declaration

Here is the entire sample code



namespace Samples
{
using System;
using System.Collections.Generic;
using System.Xml.Serialization;

public class Sample
{
public static void Main(string[] args)
{
List<Job> jobs = new List<Job>();
jobs.Add(new Job() { Company = "ACME", Location = new Location() { City = "Hollywood" } });
jobs.Add(new Job() { Company = "Black Mesa", Location = new Location() { City = "New Mexico" } });
XmlSerializer x = new XmlSerializer(jobs.GetType(), new XmlRootAttribute("Jobs"));
x.Serialize(Console.Out, jobs);
Console.ReadLine();
}
}

public class Job
{
public string Company { get; set; }
public Location Location { get; set; }
}

public class Location
{
public string City { get; set; }
}
}


No comments:

Post a Comment