当前位置: 首页>>代码示例>>C#>>正文


C# XElement.ElementAsString方法代码示例

本文整理汇总了C#中System.Xml.Linq.XElement.ElementAsString方法的典型用法代码示例。如果您正苦于以下问题:C# XElement.ElementAsString方法的具体用法?C# XElement.ElementAsString怎么用?C# XElement.ElementAsString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Xml.Linq.XElement的用法示例。


在下文中一共展示了XElement.ElementAsString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Parse

        internal override void Parse(XElement element)
        {
            Id = element.ElementAsInt("id");
            Title = element.ElementAsString("title");

            var authorElement = element.Element("author");
            if (authorElement != null)
            {
                AuthorId = authorElement.ElementAsInt("id");
                AuthorName = authorElement.ElementAsString("name");
            }

            ImageUrl = element.ElementAsString("image_url");
        }
开发者ID:yceron,项目名称:goodreads-dotnet,代码行数:14,代码来源:BestBook.cs

示例2: Parse

        /// <summary>
        /// Parse an actor xml element and returns null if xml not valid
        /// </summary>
        /// <param name="actorXml">Actor xml element</param>
        /// <returns>Returns parsed actor or null if xml is not valid</returns>
        public TheTvDbActor Parse(XElement actorXml)
        {
            if (actorXml == null) throw new ArgumentNullException(nameof(actorXml));

            // If actor has no id throw ParseException
            var id = actorXml.ElementAsUInt("id");
            if (!id.HasValue) throw new TheTvDbParseException("Error while parsing an actor xml element. EpisodeId is missing.");

            return new TheTvDbActor(id.Value)
            {
                ImageRemotePath = actorXml.ElementAsString("Image"),
                Name = actorXml.ElementAsString("Name"),
                Role = actorXml.ElementAsString("Role"),
                SortOrder = actorXml.ElementAsInt("SortOrder").GetValueOrDefault()
            };
        }
开发者ID:StuartMeeks,项目名称:TheTVDBSharp,代码行数:21,代码来源:TheTvDbActorParser.cs

示例3: Parse

 internal override void Parse(XElement element)
 {
     Id = element.ElementAsInt("id");
     Status = element.ElementAsString("status");
     UpdatedAt = element.ElementAsDateTime("updated_at");
     RatingsCount = element.ElementAsInt("ratings_count");
     CommentsCount = element.ElementAsInt("comments_count");
 }
开发者ID:yceron,项目名称:goodreads-dotnet,代码行数:8,代码来源:ReadStatus.cs

示例4: Parse

        /// <summary>
        /// Parse episode xml element and returns null if xml is not valid
        /// </summary>
        /// <param name="episodeXml">Episode xml element</param>
        /// <returns>Return parsed episode or null if xml is not valid</returns>
        public TheTvDbEpisode Parse(XElement episodeXml)
        {
            if (episodeXml == null) throw new ArgumentNullException(nameof(episodeXml));

            // If episode has no id or number skip parsing and return null
            var id = episodeXml.ElementAsUInt("id");
            if (!id.HasValue) throw new TheTvDbParseException("Error while parsing an episode xml element. Id is missing.");

            var number = episodeXml.ElementAsInt("EpisodeNumber");
            if (!number.HasValue) throw new TheTvDbParseException("Error while parsing an episode xml element. EpisodeNumber is missing.");

            return new TheTvDbEpisode(id.Value)
            {
                SeasonId = episodeXml.ElementAsUInt("seasonid"),
                SeasonNumber = episodeXml.ElementAsUInt("SeasonNumber"),
                EpisodeNumber = number.Value,
                EpisodeName = episodeXml.ElementAsString("EpisodeName"),
                SeriesId = episodeXml.ElementAsUInt("seriesId"),
                FirstAired = episodeXml.ElementAsDateTime("FirstAired"),
                Directors = episodeXml.ElementAsString("Director").SplitByPipe(),
                GuestStars = episodeXml.ElementAsString("GuestStars").SplitByPipe(),
                Description = episodeXml.ElementAsString("Overview", true),
                Rating = episodeXml.ElementAsDouble("Rating"),
                Writers = episodeXml.ElementAsString("Writer").SplitByPipe(),
                RatingCount = episodeXml.ElementAsInt("RatingCount"),
                ThumbWidth = episodeXml.ElementAsInt("thumb_width"),
                ThumbHeight = episodeXml.ElementAsInt("thumb_height"),
                ThumbRemotePath = episodeXml.ElementAsString("filename"),
                Language = episodeXml.ElementAsString("Language").ToTheTvDbLanguage(),
                LastUpdated = episodeXml.ElementFromEpochToDateTime("lastupdated")
            };
        }
开发者ID:StuartMeeks,项目名称:TheTVDBSharp,代码行数:37,代码来源:TheTvDbEpisodeParser.cs

示例5: Parse

        /// <summary>
        /// Parse banner xml element and returns null if xml is not valid
        /// </summary>
        /// <param name="bannerXml">Banner xml element</param>
        /// <returns>Return the created banner or null if xml is not valid</returns>
        public TheTvDbBanner Parse(XElement bannerXml)
        {
            if (bannerXml == null) throw new ArgumentNullException(nameof(bannerXml));

            TheTvDbBanner banner;

            // If banner has no id return null
            var id = bannerXml.ElementAsUInt("id");
            if (!id.HasValue) throw new TheTvDbParseException("Error while parsing a banner xml element. Banner id is missing.");

            var bannerType = bannerXml.ElementAsString("BannerType");
            switch (bannerType)
            {
                case "fanart":
                    banner = CreateFanart(bannerXml, id.Value);
                    break;
                case "poster":
                    banner = CreatePoster(bannerXml, id.Value);
                    break;
                case "season":
                    banner = CreateSeason(bannerXml, id.Value);
                    break;
                case "series":
                    banner = CreateSeries(bannerXml, id.Value);
                    break;
                default:
                    throw new TheTvDbParseException(
                        $"Error while parsing a banner xml element. BannerType '{bannerType}' is unknown.");
            }

            banner.Language = bannerXml.ElementAsString("Language").ToTheTvDbLanguage();
            banner.Rating = bannerXml.ElementAsDouble("Rating");
            banner.RatingCount = bannerXml.ElementAsInt("RatingCount");
            banner.RemotePath = bannerXml.ElementAsString("BannerPath");

            return banner;
        }
开发者ID:StuartMeeks,项目名称:TheTVDBSharp,代码行数:42,代码来源:TheTvDbBannerParser.cs

示例6: Parse

        internal override void Parse(XElement element)
        {
            Id = element.ElementAsInt("id");
            Body = element.ElementAsString("body");

            var userElement = element.Element("user");
            if (userElement != null)
            {
                User = new UserSummary();
                User.Parse(userElement);
            }

            CreatedAt = element.ElementAsDateTime("created_at");
            UpdatedAt = element.ElementAsDateTime("updated_at");
        }
开发者ID:yceron,项目名称:goodreads-dotnet,代码行数:15,代码来源:Comment.cs

示例7: CreateFanart

        private static TheTvDbBanner CreateFanart(XElement bannerXml, uint id)
        {
            if (bannerXml == null) throw new ArgumentNullException(nameof(bannerXml));

            var banner = new TheTvDbFanArtBanner(id);

            var size = ParseSize(bannerXml.ElementAsString("BannerType2"));
            if (size != null)
            {
                banner.Width = size.Item1;
                banner.Height = size.Item2;
            }

            var colorRawCollection = bannerXml.ElementAsString("Colors").SplitByPipe();
            if (colorRawCollection != null)
            {
                banner.Colors = colorRawCollection
                    .Select(c =>
                    {
                        var colorRawParts = c.Split(',');
                        return new TheTvDbColor(
                            byte.Parse(colorRawParts[0]),
                            byte.Parse(colorRawParts[1]),
                            byte.Parse(colorRawParts[2])
                            );
                    })
                    .ToList();
            }

            banner.RemoteThumbnailPath = bannerXml.ElementAsString("ThumbnailPath");
            banner.RemoteVignettePath = bannerXml.ElementAsString("VignettePath");

            return banner;
        }
开发者ID:StuartMeeks,项目名称:TheTVDBSharp,代码行数:34,代码来源:TheTvDbBannerParser.cs

示例8: CreateSeason

        private static TheTvDbBanner CreateSeason(XElement bannerXml, uint id)
        {
            if (bannerXml == null) throw new ArgumentNullException(nameof(bannerXml));

            return new TheTvDbSeasonBanner(id)
            {
                Season = bannerXml.ElementAsInt("Season"),
                IsWide = bannerXml.ElementAsString("BannerType2") == "seasonwide"
            };
        }
开发者ID:StuartMeeks,项目名称:TheTVDBSharp,代码行数:10,代码来源:TheTvDbBannerParser.cs

示例9: CreatePoster

        private static TheTvDbBanner CreatePoster(XElement bannerXml, uint id)
        {
            if (bannerXml == null) throw new ArgumentNullException(nameof(bannerXml));

            var banner = new TheTvDbPosterBanner(id);

            var size = ParseSize(bannerXml.ElementAsString("BannerType2"));
            if (size == null) return banner;

            banner.Width = size.Item1;
            banner.Height = size.Item2;

            return banner;
        }
开发者ID:StuartMeeks,项目名称:TheTVDBSharp,代码行数:14,代码来源:TheTvDbBannerParser.cs

示例10: Parse

 internal override void Parse(XElement element)
 {
     Id = element.ElementAsInt("id");
     Name = element.ElementAsString("name");
     Role = element.ElementAsString("role");
     ImageUrl = element.ElementAsString("image_url");
     SmallImageUrl = element.ElementAsString("small_image_url");
     Link = element.ElementAsString("link");
     AverageRating = element.ElementAsNullableDecimal("average_rating");
     RatingsCount = element.ElementAsNullableInt("ratings_count");
     TextReviewsCount = element.ElementAsNullableInt("text_reviews_count");
 }
开发者ID:yceron,项目名称:goodreads-dotnet,代码行数:12,代码来源:AuthorSummary.cs

示例11: Parse

        internal override void Parse(XElement element)
        {
            Id = element.ElementAsInt("id");
            Title = element.ElementAsString("title");
            TitleWithoutSeries = element.ElementAsString("title_without_series");
            Link = element.ElementAsString("link");
            ImageUrl = element.ElementAsString("image_url");
            SmallImageUrl = element.ElementAsString("small_image_url");
            Isbn = element.ElementAsString("isbn");
            Isbn13 = element.ElementAsString("isbn13");
            AverageRating = element.ElementAsNullableDecimal("average_rating");
            RatingsCount = element.ElementAsNullableInt("ratings_count");
            PublicationDate = element.ElementAsMultiDateField("publication");
            Authors = element.ParseChildren<AuthorSummary>("authors", "author");

            var workElement = element.Element("work");
            if (workElement != null)
            {
                WorkId = workElement.ElementAsNullableInt("id");
            }
        }
开发者ID:yceron,项目名称:goodreads-dotnet,代码行数:21,代码来源:BookSummary.cs

示例12: Parse

        internal override void Parse(XElement element)
        {
            Id = element.ElementAsInt("id");

            var bestBookElement = element.Element("best_book");
            if (bestBookElement != null)
            {
                BestBook = new BestBook();
                BestBook.Parse(bestBookElement);
            }

            BestBookId = element.ElementAsNullableInt("best_book_id");
            BooksCount = element.ElementAsInt("books_count");
            ReviewsCount = element.ElementAsInt("reviews_count");
            RatingsSum = element.ElementAsInt("ratings_sum");
            RatingsCount = element.ElementAsInt("ratings_count");
            TextReviewsCount = element.ElementAsInt("text_reviews_count");

            // Merge the Goodreads publication fields into one date property
            var originalPublicationYear = element.ElementAsInt("original_publication_year");
            var originalPublicationMonth = element.ElementAsInt("original_publication_month");
            var originalPublicationDay = element.ElementAsInt("original_publication_day");
            if (originalPublicationYear != 0 && originalPublicationMonth != 0 && originalPublicationDay != 0)
            {
                OriginalPublicationDate = new DateTime(originalPublicationYear, originalPublicationMonth, originalPublicationDay);
            }

            OriginalTitle = element.ElementAsString("original_title");
            OriginalLanguageId = element.ElementAsNullableInt("original_language_id");
            MediaType = element.ElementAsString("media_type");

            // Parse out the rating distribution
            var ratingDistributionElement = element.ElementAsString("rating_dist");
            if (ratingDistributionElement != null)
            {
                var parts = ratingDistributionElement.Split('|');
                if (parts != null && parts.Length > 0)
                {
                    var ratingDistribution = new Dictionary<int, int>();

                    var ratings = parts.Select(x => x.Split(':'))
                                       .Where(x => x[0] != "total")
                                       .OrderBy(x => x[0]);

                    foreach (var rating in ratings)
                    {
                        int star = 0, count = 0;
                        int.TryParse(rating[0], out star);
                        int.TryParse(rating[1], out count);

                        ratingDistribution.Add(star, count);
                    }

                    RatingDistribution = ratingDistribution;
                }
            }
        }
开发者ID:yceron,项目名称:goodreads-dotnet,代码行数:57,代码来源:Work.cs

示例13: ParseBannerUpdate

        private static TheTvDbBannerUpdate ParseBannerUpdate(XElement bannerUpdateXml)
        {
            if (bannerUpdateXml == null) throw new ArgumentNullException(nameof(bannerUpdateXml));

            return new TheTvDbBannerUpdate
            {
                SeriesId = bannerUpdateXml.ElementAsUInt("Series").GetValueOrDefault(),
                RemotePath = bannerUpdateXml.ElementAsString("path"),
                SeasonNumber = bannerUpdateXml.ElementAsUInt("SeasonNum"),
                Language = bannerUpdateXml.ElementAsString("language").ToTheTvDbLanguage(),
                LastUpdated = bannerUpdateXml.ElementFromEpochToDateTime("time").GetValueOrDefault()
            };
        }
开发者ID:StuartMeeks,项目名称:TheTVDBSharp,代码行数:13,代码来源:TheTvDbUpdateParser.cs

示例14: Parse

 internal override void Parse(XElement element)
 {
     Id = element.ElementAsInt("id");
     Name = element.ElementAsString("name");
     Link = element.ElementAsString("link");
     ImageUrl = element.ElementAsString("image_url");
     SmallImageUrl = element.ElementAsString("small_image_url");
     FriendsCount = element.ElementAsInt("friends_count");
     ReviewsCount = element.ElementAsInt("reviews_count");
     CreatedAt = element.ElementAsDateTime("created_at");
 }
开发者ID:yceron,项目名称:goodreads-dotnet,代码行数:11,代码来源:UserSummary.cs

示例15: Parse

        /// <summary>
        /// Parse series metadata as xml element and returns null if xml is not valid (series has no id) 
        /// </summary>
        /// <param name="seriesXml">Series metadata as xml element</param>
        /// <param name="isSearchElement"></param>
        /// <returns>Returns the successfully parsed series</returns>
        public TheTvDbSeries Parse(XElement seriesXml, bool isSearchElement = false)
        {
            if (seriesXml == null) throw new ArgumentNullException(nameof(seriesXml));

            // If series has no id throw ParseException
            var id = seriesXml.ElementAsUInt("id");
            if (!id.HasValue) throw new TheTvDbParseException("Error while parsing a series xml element. Id is missing.");

            var series = new TheTvDbSeries(id.Value)
            {
                ImdbId = seriesXml.ElementAsString("IMDB_ID"),
                SeriesName = seriesXml.ElementAsString("SeriesName", true),
                Language = seriesXml.ElementAsString(isSearchElement ? "language" : "Language").ToTheTvDbLanguage(),
                Network = seriesXml.ElementAsString("Network"),
                Description = seriesXml.ElementAsString("Overview", true),
                Rating = seriesXml.ElementAsDouble("Rating"),
                RatingCount = seriesXml.ElementAsInt("RatingCount"),
                Runtime = seriesXml.ElementAsInt("Runtime"),
                BannerRemotePath = seriesXml.ElementAsString("banner"),
                FanartRemotePath = seriesXml.ElementAsString("fanart"),
                LastUpdated = seriesXml.ElementFromEpochToDateTime("lastupdated"),
                PosterRemotePath = seriesXml.ElementAsString("poster"),
                Zap2ItId = seriesXml.ElementAsString("zap2it_id"),
                FirstAired = seriesXml.ElementAsDateTime("FirstAired"),
                AirTime = seriesXml.ElementAsTimeSpan("Airs_Time"),
                AirDay = seriesXml.ElementAsEnum<TheTvDbFrequency>("Airs_DayOfWeek"),
                Status = seriesXml.ElementAsEnum<TheTvDbStatus>("Status"),
                ContentRating = seriesXml.ElementAsString("ContentRating").ToTheTvDbContentRating(),
                Genres = seriesXml.ElementAsString("Genre").SplitByPipe()
            };

            if (series.FirstAired.HasValue)
            {
                series.SeriesName = series.SeriesName.Replace(string.Format(" ({0})", series.FirstAired.Value.Year), "");
            }

            return series;
        }
开发者ID:StuartMeeks,项目名称:TheTVDBSharp,代码行数:44,代码来源:TheTvDbSeriesParser.cs


注:本文中的System.Xml.Linq.XElement.ElementAsString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。