Last active
August 29, 2015 14:04
-
-
Save margusmartsepp/589447acfafc3e9c1b96 to your computer and use it in GitHub Desktop.
TanelExample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.IO; | |
| using System.Linq; | |
| using System.Text; | |
| using System.Threading.Tasks; | |
| using System.Xml; | |
| using System.Xml.Serialization; | |
| namespace AgentImporter | |
| { | |
| public class TanelExample | |
| { | |
| private TanelExample() { } | |
| public static Master Of(string xml) | |
| { | |
| var ser = new XmlSerializer(typeof(Master)); | |
| using (var reader = XmlReader.Create(new StringReader(xml))) | |
| { | |
| return (Master)ser.Deserialize(reader); | |
| } | |
| } | |
| public static string xml = @" | |
| <objects> | |
| <object publicationid='52AA9ABA-981C-4C9C-9287-0BAC04DEB114' type='Videogallery'> | |
| <idc>5AD6A287-54FB-43DC-B7C7-B8F2BE8970B5</idc> | |
| <idx>Videogallery/48c8509b-959f-4be0-89da-cccd9f488df8</idx> | |
| <data> | |
| <description> | |
| <idc>5AD6A287-54FB-43DC-B7C7-B8F2BE8970B5</idc> | |
| <siteid>90C2BB91-3761-4C60-9CC9-0E25A8AE6951</siteid> | |
| <creationdate>2010-10-13T16:38:08.577</creationdate> | |
| <lastmodified>2010-10-13T16:38:08.577</lastmodified> | |
| <name /> | |
| <authorname /> | |
| <gallerydescription /> | |
| <gallerywidth>460</gallerywidth> | |
| <galleryvideowidth>460</galleryvideowidth> | |
| <galleryvideoheight>279</galleryvideoheight> | |
| <gallerythumbnailwidth>160</gallerythumbnailwidth> | |
| <gallerythumbnailheight>90</gallerythumbnailheight> | |
| <gallerydesign /> | |
| </description> | |
| <videos> | |
| <video> | |
| <id>2B6D00D8-4E32-4541-8B01-59EB9A5E750B</id> | |
| <publicationelementidc>5AD6A287-54FB-43DC-B7C7-B8F2BE8970B5</publicationelementidc> | |
| <author>Silvia Kruusmaa</author> | |
| <shooter>Veiko Tõkman</shooter> | |
| <videouri>http://video.ap3.ee/video/filmid/AndresAavik.flv</videouri> | |
| <description>Intervjuu Skanska EMV AS juhatuse esimees Andres Aavikuga.</description> | |
| <thumbnailuri>http://www.ap3.ee/images/publicationimages/fb6c7821-0da6-4b12-9873-5956be3d2b5e.jpg</thumbnailuri> | |
| <openimageurl>http://www.ap3.ee/images/publicationimages/d092200a-9f18-4612-8738-3493a5b17465.jpg</openimageurl> | |
| <formatid>00000000-0000-0000-0000-000000000000</formatid> | |
| <orderno>1</orderno> | |
| <hostsld>ap3</hostsld> | |
| <isduplicate>0</isduplicate> | |
| </video> | |
| <video> | |
| <id>2B6D40D8-4E32-4541-8B01-59EB9A5E750B</id> | |
| <publicationelementidc>5AD6A287-54FB-43DC-B7C7-B8F2BE8970B5</publicationelementidc> | |
| <author>Silvia Kruusmaa</author> | |
| <shooter>Veiko Tõkman</shooter> | |
| <videouri>http://video.ap3.ee/video/filmid/AndresAavik.flv</videouri> | |
| <description>Intervjuu Skanska EMV AS juhatuse esimees Andres Aavikuga.</description> | |
| <thumbnailuri>http://www.ap3.ee/images/publicationimages/fb6c7821-0da6-4b12-9873-5956be3d2b5e.jpg</thumbnailuri> | |
| <openimageurl>http://www.ap3.ee/images/publicationimages/d092200a-9f18-4612-8738-3493a5b17465.jpg</openimageurl> | |
| <formatid>00000000-0000-0000-0000-000000000000</formatid> | |
| <orderno>1</orderno> | |
| <hostsld>ap3</hostsld> | |
| <isduplicate>0</isduplicate> | |
| </video> | |
| </videos> | |
| </data> | |
| </object> | |
| </objects>"; | |
| [XmlType("objects")] | |
| [XmlRoot(IsNullable = false)] | |
| public partial class Master | |
| { | |
| //{"For non-array types, you may use the following attributes: XmlAttribute, XmlText, XmlElement, or XmlAnyElement."} | |
| [XmlElement(Namespace = "", ElementName = "object")] | |
| public Gallery Galleries { get; set; } | |
| } | |
| [XmlType(AnonymousType = true)] | |
| public partial class Gallery | |
| { | |
| [XmlElement(Namespace = "", ElementName = "data")] | |
| public Data Content { get; set; } | |
| } | |
| [XmlType(AnonymousType = true)] | |
| public partial class Data | |
| { | |
| [XmlElement(IsNullable = true, ElementName = "description")] | |
| public Description Descriptions { get; set; } | |
| [XmlArray("videos")] | |
| [XmlArrayItem("video", IsNullable = false)] | |
| public Video[] Videos { get; set; } | |
| [XmlType(AnonymousType = true)] | |
| public partial class Video | |
| { | |
| [XmlElement(IsNullable = true, ElementName = "author")] | |
| public string Author { get; set; } | |
| [XmlElement(IsNullable = true, ElementName = "shooter")] | |
| public string Shooter { get; set; } | |
| [XmlElement(IsNullable = true, ElementName = "videouri")] | |
| public string VideouUi { get; set; } | |
| [XmlElement(IsNullable = true, ElementName = "description")] | |
| public string Description { get; set; } | |
| [XmlElement(IsNullable = true, ElementName = "orderno")] | |
| public decimal? OrderNo { get; set; } | |
| [XmlElement(IsNullable = true, ElementName = "hostsld")] | |
| public string HostsLd { get; set; } | |
| } | |
| [XmlType(AnonymousType = true)] | |
| public partial class Description | |
| { | |
| [XmlElement(IsNullable = true, ElementName = "name")] | |
| public string Name { get; set; } | |
| [XmlElement(IsNullable = true, ElementName = "authorname")] | |
| public string AuthorName { get; set; } | |
| [XmlElement(IsNullable = true, ElementName = "gallerydescription")] | |
| public string GalleryDescription { get; set; } | |
| } | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var XmlDoc = TanelExample.Of(TanelExample.xml); | |
| var description = XmlDoc.Galleries.Content.Descriptions; | |
| XmlDoc.Galleries.Content.Videos.Select(video => new //Classname | |
| { | |
| video.Author, | |
| video.Description, | |
| video.HostsLd, | |
| video.OrderNo, | |
| video.Shooter, | |
| videoUri = video.VideouU, | |
| description.AuthorName, | |
| description.GalleryDescription, | |
| description.Name | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment