//============================================================ // PUBLIC METHODS //============================================================ #region Load(XPathNavigator source) /// <summary> /// Loads this <see cref="ITunesCategory"/> using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <returns><b>true</b> if the <see cref="ITunesCategory"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns> /// <remarks> /// This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="ITunesCategory"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> public bool Load(XPathNavigator source) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ bool wasLoaded = false; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(source, "source"); //------------------------------------------------------------ // Create namespace manager to resolve prefixed elements //------------------------------------------------------------ ITunesSyndicationExtension extension = new ITunesSyndicationExtension(); XmlNamespaceManager manager = extension.CreateNamespaceManager(source); //------------------------------------------------------------ // Attempt to extract syndication information //------------------------------------------------------------ if (source.HasAttributes) { string textAttribute = source.GetAttribute("text", String.Empty); if (!String.IsNullOrEmpty(textAttribute)) { this.Text = textAttribute; wasLoaded = true; } } if (source.HasChildren) { XPathNodeIterator categoryIterator = source.Select("itunes:category", manager); if (categoryIterator != null && categoryIterator.Count > 0) { while (categoryIterator.MoveNext()) { ITunesCategory category = new ITunesCategory(); if (category.Load(categoryIterator.Current)) { this.Categories.Add(category); wasLoaded = true; } } } } return(wasLoaded); }
/// <summary> /// Loads this <see cref="ITunesCategory"/> using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <returns><b>true</b> if the <see cref="ITunesCategory"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns> /// <remarks> /// This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="ITunesCategory"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> public bool Load(XPathNavigator source) { bool wasLoaded = false; Guard.ArgumentNotNull(source, "source"); ITunesSyndicationExtension extension = new ITunesSyndicationExtension(); XmlNamespaceManager manager = extension.CreateNamespaceManager(source); if (source.HasAttributes) { string textAttribute = source.GetAttribute("text", String.Empty); if (!String.IsNullOrEmpty(textAttribute)) { this.Text = textAttribute; wasLoaded = true; } } if (source.HasChildren) { XPathNodeIterator categoryIterator = source.Select("itunes:category", manager); if (categoryIterator != null && categoryIterator.Count > 0) { while (categoryIterator.MoveNext()) { ITunesCategory category = new ITunesCategory(); if (category.Load(categoryIterator.Current)) { this.Categories.Add(category); wasLoaded = true; } } } } return(wasLoaded); }
/// <summary> /// Initializes the common syndication extension information using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="source">The <b>XPathNavigator</b> used to load this <see cref="ITunesSyndicationExtensionContext"/>.</param> /// <param name="manager">The <see cref="XmlNamespaceManager"/> object used to resolve prefixed syndication extension elements and attributes.</param> /// <returns><b>true</b> if the <see cref="ITunesSyndicationExtensionContext"/> was able to be initialized using the supplied <paramref name="source"/>; otherwise <b>false</b>.</returns> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="manager"/> is a null reference (Nothing in Visual Basic).</exception> private bool LoadCommon(XPathNavigator source, XmlNamespaceManager manager) { bool wasLoaded = false; Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(manager, "manager"); if (source.HasChildren) { XPathNavigator authorNavigator = source.SelectSingleNode("itunes:author", manager); XPathNavigator keywordsNavigator = source.SelectSingleNode("itunes:keywords", manager); XPathNavigator newFeedUrlNavigator = source.SelectSingleNode("itunes:new-feed-url", manager); XPathNavigator ownerNavigator = source.SelectSingleNode("itunes:owner", manager); XPathNavigator subtitleNavigator = source.SelectSingleNode("itunes:subtitle", manager); XPathNavigator summaryNavigator = source.SelectSingleNode("itunes:summary", manager); XPathNodeIterator categoryIterator = source.Select("itunes:category", manager); if (authorNavigator != null && !String.IsNullOrEmpty(authorNavigator.Value)) { this.Author = authorNavigator.Value; wasLoaded = true; } if (keywordsNavigator != null && !String.IsNullOrEmpty(keywordsNavigator.Value)) { if (keywordsNavigator.Value.Contains(",")) { string[] keywords = keywordsNavigator.Value.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); foreach (string keyword in keywords) { this.Keywords.Add(keyword); wasLoaded = true; } } else { this.Keywords.Add(keywordsNavigator.Value); wasLoaded = true; } } if (newFeedUrlNavigator != null) { Uri newFeedUrl; if (Uri.TryCreate(newFeedUrlNavigator.Value, UriKind.RelativeOrAbsolute, out newFeedUrl)) { this.NewFeedUrl = newFeedUrl; wasLoaded = true; } } if (ownerNavigator != null) { ITunesOwner owner = new ITunesOwner(); if (owner.Load(ownerNavigator)) { this.Owner = owner; wasLoaded = true; } } if (subtitleNavigator != null && !String.IsNullOrEmpty(subtitleNavigator.Value)) { this.Subtitle = subtitleNavigator.Value; wasLoaded = true; } if (summaryNavigator != null && !String.IsNullOrEmpty(summaryNavigator.Value)) { this.Summary = summaryNavigator.Value; wasLoaded = true; } if (categoryIterator != null && categoryIterator.Count > 0) { while (categoryIterator.MoveNext()) { ITunesCategory category = new ITunesCategory(); if (category.Load(categoryIterator.Current)) { this.Categories.Add(category); wasLoaded = true; } } } } return(wasLoaded); }