XML to List of Class C#
if we have XML file like this :
we can use This Code to return List of Class
- <code>
- <picturecollection>
- <photo>
- <name>One</name>
- <path>somepath1</path>
- </photo>
- <photo>
- <name>Two</name>
- <path>somepath2</path>
- </photo>
- </picturecollection>
- </code>
we can use This Code to return List of Class
- <code>
- <div style="overflow-x: scroll;">
- <div style="width: 1324px;">
- XDocument xdoc = XDocument.Load(Server.MapPath(@"\Photo.xml"));
- List<pic> pics = (from xml in xdoc.Elements("PictureCollection").Elements("Photo")
- select new Pic
- {
- PicName = xml.Element("name").Value,
- TbPath = xml.Element("path").Value
- }).ToList();
- </pic></div>
- </div>
- </code>
- <code>
- public class Pic
- {
- public string PicName {get; set;}
- public string TbPath { get; set; }
- }
- </code>