I want to write university courses in an xml file and be sorted by departments. So if I add a course from different departments I will get something like:
<Departments>
<FST_Department>
<Course_Details>
<Course_Name >Networking</Course_Name>
<Course_Code >xx</Course_Code>
</Course_Details>
</FST_Department >
<Medicine_Department>
<Course_Details>
<Course_Name >General_Medicine</Course_Name>
<Course_Code >xxxxxxx</Course_Code>
</Course_Details>
</Medicine_Department>
</Departments
But instead all my courses go inside the last department I added a course to and the other department 'tags' disapear.Like below.
<Departments>
<Medicine_Department>
<Course_Details>
<Course_Name >Networking</Course_Name>
<Course_Code >xx</Course_Code>
</Course_Details>
<Course_Details>
<Course_Name >General Medicine</Course_Name>
<Course_Code >xxxxxxx</Course_Code>
</Course_Details>
</Medicine_Department>
</Departments
The code to create the xml file .
string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
if (!Directory.Exists(path = "E:\\Sorting\\Directory"))
Directory.CreateDirectory(path = "E:\\Sorting\\Directory");
if (!File.Exists(path = "E:\\Sorting\\Directory\\Sort.xml"))
{
XmlTextWriter xW = new XmlTextWriter(path ="E:\\Sorting\\Directory\\Sort.xml", Encoding.UTF8);
xW.WriteStartElement("Departments");//my root
xW.WriteEndElement(); // Departments
xW.Close();
This is the code I use to add data to the xml file :
string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
XmlDocument xDoc = new XmlDocument();
xDoc.Load("E:\\Sorting\\Directory\\Sort.xml");
XmlNode xNode = xDoc.SelectSingleNode("Departments");
xNode.RemoveAll();
if (combboBox.Text == "FST")
{
XmlNode xDepartmentNode = xDoc.CreateElement("FST_Department");
foreach (Course c in courses)
{
XmlNode xCourse_Details = xDoc.CreateElement("Course_Details");
XmlNode xCode = xDoc.CreateElement("Course_Code");
xCode.InnerText = c.courseCode;
xCourse_Details.AppendChild(xCode);
XmlNode xName = xDoc.CreateElement("Course_Name");
xName.InnerText = c.courseName;
xCourse_Details.AppendChild(xName);
xDepartmentNode.AppendChild(xCourse_Details);
xDoc.DocumentElement.AppendChild(xDepartmentNode);
xDoc.Save("E:\\Sorting\\Directory\\Sort.xml");
}
}
else if(combbobox.Text == "Medicine")
{
XmlNode xDepartmentNode = xDoc.CreateElement("Medicine_Department");
foreach (Course c in courses)
{
XmlNode xCourse_Details = xDoc.CreateElement("Course_Details");
XmlNode xCode = xDoc.CreateElement("Course_Code");
xCode.InnerText = c.courseCode;
xCourse_Details.AppendChild(xCode);
XmlNode xName = xDoc.CreateElement("Course_Name");
xName.InnerText = c.courseName;
xCourse_Details.AppendChild(xName);
xDepartmentNode.AppendChild(xCourse_Details);
xDoc.DocumentElement.AppendChild(xDepartmentNode);
xDoc.Save("E:\\Sorting\\Directory\\Sort.xml");
}
}
You clear all departments with this line. So anything that was there before is wiped from the file:
xNode.RemoveAll();
Second, with your foreach on courses, you will add all the courses to that department. Since you neither sort or filter the courses by department, you are getting them all into whatever department combobox.Text is selecting.
Scrap it and use XML Serialization lol
Departments Class
using System.Xml.Serialization;
namespace Serializer
{
public class Departments
{
public FST_Department FST_Department { get; set; }
public Medicine_Department Medicine_Department { get; set; }
}
}
FST_Department Class
using System.Collections.Generic;
namespace Serializer
{
public class FST_Department
{
public List<Course> Course_Details { get; set; }
}
}
Medicine_Department Class
using System.Collections.Generic;
namespace Serializer
{
public class Medicine_Department
{
public List<Course> Course_Details { get; set; }
}
}
Course Class
namespace Serializer
{
public class Course
{
public string Course_Name { get; set; }
public string Course_Code { get; set; }
}
}
Read and write serialized xml
using System.Collections.Generic;
using System.Xml.Serialization;
using System.IO;
namespace Serializer
{
class XMLManager
{
private const string configFileName = "Departments.xml";
public static Departments Read()
{
XmlSerializer reader = new XmlSerializer(typeof(Departments));
using (FileStream file = File.OpenRead(Path.Combine(Global.AppRoot, configFileName)))
{
return reader.Deserialize(file) as Departments;
}
}
public static void Write(Departments settings)
{
XmlSerializer writer = new XmlSerializer(typeof(Departments));
using (FileStream file = File.Create(Path.Combine(Global.AppRoot, configFileName)))
{
writer.Serialize(file, settings);
}
}
}
}
Usage
Departments depart = new Departments();
FST_Department fst = new FST_Department();
fst.Course_Details = new List<Course>();
Course course = new Course();
course.Course_Code = "1";
course.Course_Name = "Test 1";
fst.Course_Details.Add(course);
course = new Course();
course.Course_Code = "2";
course.Course_Name = "Test2";
fst.Course_Details.Add(course);
depart.FST_Department = fst;
Medicine_Department med = new Medicine_Department();
med.Course_Details = new List<Course>();
course = new Course();
course.Course_Code = "3";
course.Course_Name = "Test 3";
med.Course_Details.Add(course);
depart.Medicine_Department = med;
//put it all in some kind of order in case things were added out of order
depart.FST_Department.Course_Details.OrderBy(c => c.Course_Code);
depart.Medicine_Department.Course_Details.OrderBy(c => c.Course_Code);
XMLManager.Write(depart);
XML File Output
<?xml version="1.0"?>
<Departments xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<FST_Department>
<Course_Details>
<Course>
<Course_Name>Test 1</Course_Name>
<Course_Code>1</Course_Code>
</Course>
<Course>
<Course_Name>Test2</Course_Name>
<Course_Code>2</Course_Code>
</Course>
</Course_Details>
</FST_Department>
<Medicine_Department>
<Course_Details>
<Course>
<Course_Name>Test 3</Course_Name>
<Course_Code>3</Course_Code>
</Course>
</Course_Details>
</Medicine_Department>
</Departments>
Related
Let me explain, there is a database table which has 1 XML column named audits and other common types of column.
so is this possible to deserialize below XML into class.
<?xml version="1.0"?>
<entity type="Order">
<id type="System.Int64">146</id>
<ordernumber type="System.String">OD555</ordernumber>
<audits type='System.String'>
<audit>
<item>
<create timestamp='2017-07-19 10:02:13' userid='23' />
</item>
<invoice>
<create timestamp='2017-07-19 10:03:37' userid='45' />
</invoice>
</audit>
</audits>
</entity>
Class:
public class Order
{
public long id { get; set; }
public string ordernumber { get; set; }
public string audits { get; set; }
}
Modifying your model with the attributes XmlType and XmlAnyElement (requires XmlElement as type)
[XmlType("entity")]
public class Order
{
public long id { get; set; }
public string ordernumber { get; set; }
[XmlAnyElement]
public XmlElement audits { get; set; }
}
allows to deserialize the complete XML string like
using (MemoryStream stream = new MemoryStream())
using (StreamWriter writer = new StreamWriter(stream))
{
writer.Write(xmlString);
writer.Flush();
stream.Position = 0;
XmlSerializer serializer = new XmlSerializer(typeof(Order));
Order o = (Order)serializer.Deserialize(stream);
}
Now you are able to get the audits as string like
string auditsString = o.audits.InnerXml;
You can also add a property to your model to simplify the access:
public string auditsString
{
get
{
return audits.InnerXml;
}
}
Try xml linq :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
namespace ConsoleApplication68
{
class Program
{
const string FILENAME = #"c:\temp\test.xml";
static void Main(string[] args)
{
XDocument doc = XDocument.Load(FILENAME);
Order order = doc.Descendants("entity").Select(x => new Order()
{
id = (long)x.Element("id"),
ordernumber = (string)x.Element("ordernumber"),
audits = x.Descendants("create").Select(y => (DateTime)y.Attribute("timestamp")).ToList()
}).FirstOrDefault();
}
}
public class Order
{
public long id { get; set; }
public string ordernumber { get; set; }
public List<DateTime> audits { get; set; }
}
}
You can try like this
const string xmlString = #"<columns><column><c1>100</c1><c2>200</c2><cn>300</cn></column><column><c1>111</c1><c2>222</c2><cn>333</cn></column> <column> <c1>MAX Newsletter</c1><c2>OLS Application</c2> <cn>Total funded accounts</cn> </column></columns>";
XDocument doc = XDocument.Parse(xmlString);
if (doc.Root != null)
{
List<Row> items = (from r in doc.Root.Elements("column")
select new Row
{
C1 = (string)r.Element ("C1"),
C2 = (string)r.Element("C2"),
}).ToList();
I'm trying to read a xml file from a c# application. so far no luck at all. This is the XML file
<?xml version="1.0" encoding="utf-8"?>
<ExportJobs xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<JobList>
<Job Id="555555">
<Comments></Comments>
<DueDate>2017-11-17</DueDate>
<FormattedDueDate>17-Nov-2017 12:00</FormattedDueDate>
<TargetDueDate>2017-11-17</TargetDueDate>
<ServiceTypeId>3</ServiceTypeId>
<ServiceType>Service</ServiceType>
<TenantName>Miss Ash</TenantName>
<Uprn>testUpr</Uprn>
<HouseName></HouseName>
</Job>
<Job Id="666666">
<Comments></Comments>
<DueDate>2018-03-15</DueDate>
<FormattedDueDate>15-Mar-2018 12:00</FormattedDueDate>
<TargetDueDate>2018-03-15</TargetDueDate>
<ServiceTypeId>3</ServiceTypeId>
<ServiceType>Service</ServiceType>
<TenantName>Mr Howard</TenantName>
<Uprn>testUpr2</Uprn>
</Job>
</JobList>
</ExportJobs>
I'm trying to get the job Id and the Uprn from the joblist node and pass the values in to Sql Server DB. I tried this, but I can't get the values,
string costCode;
string uprn;
//File path where the xml is located
string filepath = "C:\\ExportJobs.xml";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(filepath);
foreach (XmlNode node in xmlDoc.DocumentElement.ChildNodes)
{
costCode = node.Attributes["Id"].InnerText;
uprn = node.Attributes["Uprn"].InnerText;
}
I really appreciate any help. Thanks
XmlSerializer is your friend:
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;
public class ExportJobs
{
public List<Job> JobList { get; } = new List<Job>();
}
public class Job
{
[XmlAttribute]
public int Id { get; set; }
public string Comments { get; set; }
public DateTime DueDate { get; set; }
public string FormattedDueDate { get; set; }
public DateTime TargetDueDate{ get; set; }
public int ServiceTypeId { get; set; }
public string ServiceType { get; set; }
public string TenantName { get; set; }
public string Uprn { get; set; }
public string HouseName { get; set; }
}
static class P
{
static void Main()
{
var ser = new XmlSerializer(typeof(ExportJobs));
ExportJobs jobs;
using (var sr = new StringReader(xml))
{
jobs = (ExportJobs) ser.Deserialize(sr);
}
foreach(var job in jobs.JobList)
{
Console.WriteLine($"{job.Id} / {job.Uprn}: {job.DueDate}");
}
}
const string xml = #"<?xml version=""1.0"" encoding=""utf-8""?>
<ExportJobs xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
<JobList>
<Job Id=""555555"">
<Comments></Comments>
<DueDate>2017-11-17</DueDate>
<FormattedDueDate>17-Nov-2017 12:00</FormattedDueDate>
<TargetDueDate>2017-11-17</TargetDueDate>
<ServiceTypeId>3</ServiceTypeId>
<ServiceType>Service</ServiceType>
<TenantName>Miss Ash</TenantName>
<Uprn>testUpr</Uprn>
<HouseName></HouseName>
</Job>
<Job Id=""666666"">
<Comments></Comments>
<DueDate>2018-03-15</DueDate>
<FormattedDueDate>15-Mar-2018 12:00</FormattedDueDate>
<TargetDueDate>2018-03-15</TargetDueDate>
<ServiceTypeId>3</ServiceTypeId>
<ServiceType>Service</ServiceType>
<TenantName>Mr Howard</TenantName>
<Uprn>testUpr2</Uprn>
</Job>
</JobList>
</ExportJobs>";
}
You are accessing ChildNodes of root element, which contains only Jobs element, which in order does not contains attributes Id and Uprn.
The usual practice is to use XPath query as following:
foreach (XmlNode node in xmlDoc.DocumentElement.SelectNodes("Jobs/Job"))
{
costCode = node.Attributes["Id"].InnerText;
uprn = node.SelectSingleNode("Uprn").InnerText;
}
Note that Uprn is the node and not the node attribute.
Here is tested code. You need the namespace. See code below which is using xml linq
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
namespace ConsoleApplication67
{
class Program
{
const string FILENAME = #"c:\temp\test.xml";
static void Main(string[] args)
{
XDocument doc = XDocument.Load(FILENAME);
XElement exportJobs = doc.Root;
XNamespace ns = exportJobs.GetDefaultNamespace();
var results = exportJobs.Descendants(ns + "Job").Select(x => new {
id = (string)x.Attribute(ns + "Id"),
comment = (string)x.Element(ns + "Comments"),
dueDate = (DateTime)x.Element(ns + "DueDate"),
formattedDueDate = (DateTime)x.Element(ns + "FormattedDueDate"),
targetDueDate = (DateTime)x.Element(ns + "TargetDueDate"),
serviceTypeId = (int)x.Element(ns + "ServiceTypeId"),
serviceType = (string)x.Element(ns + "ServiceType"),
tenantName = (string)x.Element(ns + "TenantName"),
uprn = (string)x.Element(ns + "Uprn"),
houseName = (string)x.Element(ns + "HouseName")
}).ToList();
}
}
}
I think the best way to solve your problem is XDocument class.
XDocument xDoc = XDocument.Load(#"D:\1.xml");
foreach(var node in xDoc.Descendants("Job"))
{
id = node.Attribute("Id");
foreach(var subnode in node.Descendants("Uprn"))
{
uprn = subnode.Value;
}
//or like that. but check it for null before
uprn = node.Descendants("Uprn")?.First().Value
}
I'm trying to serialize using XMLSerializer and achieve the following result:
Desired xml:
<?xml version="1.0" encoding="utf-8"?>
<RootElem xmlns="http://www.example.com/rootns">
<Elem1>
<Foo>bar</Foo>
</Elem1>
<Elem2>
<x:ElemX xmlns:x="http://www.sample.net/otherns">
<x:Bar>foo</x:Bar>
</x:ElemX>
</Elem2>
</RootElem>
The content in <elem3> will be parsed alone by a system on the other end, so the xmlns:x specification will have to be on the <elemx> node, and not on the rootnode as below.
Current serialized xml, not desired:
<?xml version="1.0" encoding="utf-8"?>
<RootElem xmlns:x="http://www.sample.net/otherns" xmlns="http://www.example.com/rootns">
<Elem1>
<Foo>bar</Foo>
</Elem1>
<Elem2>
<x:ElemX>
<x:Bar>foo</x:Bar>
</x:ElemX>
</Elem2>
</RootElem>
Anyone know a standard way to instruct XmlSerializer to achieve this?
Here's the code used to generate this sample (simple c# winform application)
private void Form1_Load(object sender, EventArgs e)
{
RootElem root = new RootElem();
root.Elem1 = new NormalElement() { Foo = "bar"};
ChildClass c = new ChildClass() { Bar = "foo"};
root.Elem2 = new ElementWithChildClass() { ElemX = c };
MemoryStream ms = new MemoryStream();
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("x", "http://www.sample.net/otherns");
XmlSerializer xser = new XmlSerializer(typeof(RootElem));
XmlTextWriter tw = new XmlTextWriter(ms, Encoding.UTF8);
tw.Formatting = Formatting.Indented;
xser.Serialize(tw, root, ns);
ms.Seek(0, SeekOrigin.Begin);
StreamReader sr = new StreamReader(ms, Encoding.UTF8);
textBox1.Text = sr.ReadToEnd();
}
[XmlRoot(Namespace = "http://www.example.com/rootns")]
public class RootElem
{
public NormalElement Elem1 { get; set; }
public ElementWithChildClass Elem2 { get; set; }
}
public class NormalElement
{
public string Foo { get; set; }
}
public class ElementWithChildClass
{
[XmlElement(Namespace = "http://www.sample.net/otherns")]
public ChildClass ElemX { get; set; }
}
[XmlRoot("RefDoc", Namespace = "http://www.sample.net/otherns")]
public class ChildClass
{
public string Bar { get; set; }
}
Here I have a scenario that Create xml file dynamically and it should be serialisable. xml is like:
<person>
<personaldata>
<name>gopi</name>
<lastname>ch</lastname>
</personaladata>
<Educationaladata>
<Graduation>b.tech</graduation>
<designation>Engineer</designation>
</educationaldata>
</person>
person class has name, lastname, designation, graduation and properties
I tried this
public string CreateXmlObject(Person objPerson)
{
var objXmlDocument = new XmlDocument();
var objXpath = objXmlDocument.CreateNavigator();
var objXmlSeialiser = new XmlSerializer(objPerson.GetType());
using (var xs = objXpath.AppendChild())
{
objXmlSeialiser.Serialize(xs, objPerson);
}
return objXmlDocument.OuterXml;
}
My Problem is I have to read Specific data from Xml And Update Specific data to Xml . I want to read only Personaldata when i update, update should only apply to Personaldata Not Otherdata
Try xml linq
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string name = "gopi";
string lastname = "ch";
string graduation = "b.tech";
string designation = "Engineer";
XElement personalData = new XElement("person", new XElement[] {
new XElement("personaldata", new XElement[] {
new XElement("name", name),
new XElement("lastname", lastname)
}),
new XElement("Educationadata", new XElement[] {
new XElement("Graduation", graduation),
new XElement("designation", designation)
})
});
}
}
}
Fisrt of all your XML is invalid, all the nodes should match their closing tags. Considering your person class looks something like this:-
public class Person
{
public string name { get; set; }
public string lastname { get; set; }
public string Graduation { get; set; }
public string designation { get; set; }
}
You can easily do it with LINQ-to-XML:-
Xdocument = XDocument.Load("XMLFilePath");
List<Person> persons = (from person in xdoc.Descendants("person")
let personaldata = person.Element("personaldata")
let Educationaladata = person.Element("Educationaladata")
select new Person
{
name = (string)personaldata.Element("name"),
lastname = (string)personaldata.Element("lastname"),
Graduation = (string)Educationaladata.Element("Graduation"),
designation = (string)Educationaladata.Element("designation")
}).ToList();
sSometing like -
var xml = XDocument.Load("xml path");
var personaldata = xml.Descendents("personaldata").FirstOrDefault();
if (data != null)
{
foreach (var t in data.Descendants())
{
t.Value = "test";
}
}
I have this item Class :
public class Movie
{
public string VideoId { get; set; }
public string Title { get; set; }
}
And i have List<Movie> of this items and i use this code to Serialize to xml file:
string fileName = index + ".xml";
string serializationFile = Path.Combine(dir, fileName);
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
using (var writer = XmlWriter.Create(serializationFile, settings))
{
var serializer = new XmlSerializer(typeof(List<Movie>));
serializer.Serialize(writer, tmpList);
}
And this is the result:
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfMovie xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Movie>
<VideoId>MyId</VideoId>
<Title>MyTitle</Title>
</Movie>
<Movie>
<VideoId>MyId1</VideoId>
<Title>MyTitle1</Title>
</Movie>
<Movie>
<VideoId>MyId2</VideoId>
<Title>MyTitle2</Title>
</Movie>
<Movie>
<VideoId>MyId3</VideoId>
<Title>MyTitle3</Title>
</Movie>
</ArrayOfMovie>
And it this possible to add attribute to the ArrayOfMovie node,something like this:
<ArrayOfMovie xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" customattribute='Yes'>
Yes, you can do this using the XmlAttribute attribute. In order to do this, you need to define your custom attribute. It comes with the price of one more class that represents the array (nested in the root node). If you have no problem with this addition, then the solution can look like this:
public class ArrayOfMovie
{
// define the custom attribute
[XmlAttribute(AttributeName="CustomAttribute")]
public String Custom { get; set; }
// define the collection description
[XmlArray(ElementName="Items")]
public List<Movie> Items { get; set; }
}
public class Movie
{
public string VideoId { get; set; }
public string Title { get; set; }
}
Then create, fill and serialize as you already do - the one new thing is to fill your custom attribute:
// create and fill the list
var tmpList = new List<Movie>();
tmpList.Add(new Movie { VideoId = "1", Title = "Movie 1" });
tmpList.Add(new Movie { VideoId = "2", Title = "Movie 2" });
// create the collection
var movies = new ArrayOfMovie
{
Items = tmpList,
Custom = "yes" // fill the custom attribute
};
// serialize
using (var writer = XmlWriter.Create(serializationFile, settings))
{
var serializer = new XmlSerializer(typeof(ArrayOfMovie));
serializer.Serialize(writer, movies);
}
The XML output looks like this:
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfMovie xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
CustomAttribute="yes">
<Items>
<Movie>
<VideoId>1</VideoId>
<Title>Movie 1</Title>
</Movie>
<Movie>
<VideoId>2</VideoId>
<Title>Movie 2</Title>
</Movie>
</Items>
</ArrayOfMovie>
You could do it after serialization. The code skeleton looks like:
using (MemoryStream ms = new MemoryStream())
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
using (var writer = XmlWriter.Create(ms, settings))
{
var serializer = new XmlSerializer(typeof(List<Movie>));
serializer.Serialize(writer, tmpList);
}
ms.Position = 0;
XDocument doc = XDocument.Load(new XmlTextReader(ms));
doc.Root.Add(new XAttribute("customAttribute", "Yes"));
doc.Save(filename);
}
You would want to wrap the List<Movie> inside a class and then serialize that.
Something like the following
class Program
{
static void Main(string[] args)
{
string fileName = "abcd2.xml";
string serializationFile = Path.Combine(#"C:\", fileName);
List<Movie> tmpList = new List<Movie>();
tmpList.Add(new Movie() { VideoId = "1", Title = "Hello" });
tmpList.Add(new Movie() { VideoId = "2", Title = "ABCD" });
MovieList list = new MovieList("Yes", tmpList);
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
using (var writer = XmlWriter.Create(serializationFile, settings))
{
var serializer = new XmlSerializer(typeof(MovieList));
serializer.Serialize(writer, list);
}
}
}
public class MovieList
{
private string custom;
private List<Movie> movies;
public MovieList() { }
public MovieList(string custom, List<Movie> movies)
{
this.movies = movies;
this.custom = custom;
}
[XmlAttribute]
public string CustomAttribute
{
get { return this.custom; }
set { this.custom = value; }
}
public List<Movie> Movies
{
get
{
return movies;
}
set
{
this.movies = value;
}
}
}
public class Movie
{
public string VideoId { get; set; }
public string Title { get; set; }
}
The code can be improved a lot. This is just an example snippet. Check out the following MSDN link: http://msdn.microsoft.com/en-us/library/58a18dwa(v=vs.110).aspx