/// <summary> /// Loads this <see cref="AtomMemberResources"/> using the supplied <see cref="IXPathNavigable"/>. /// </summary> /// <param name="source">The <see cref="IXPathNavigable"/> to extract information from.</param> /// <returns><b>true</b> if the <see cref="AtomMemberResources"/> 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="AtomMemberResources"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> public override bool Load(IXPathNavigable source) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ bool wasLoaded = false; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(source, "source"); //------------------------------------------------------------ // Create navigator against source //------------------------------------------------------------ XPathNavigator navigator = source.CreateNavigator(); //------------------------------------------------------------ // Initialize XML namespace resolver //------------------------------------------------------------ XmlNamespaceManager manager = AtomUtility.CreateNamespaceManager(navigator.NameTable); //------------------------------------------------------------ // Attempt to extract common attributes information //------------------------------------------------------------ if (AtomUtility.FillCommonObjectAttributes(this, navigator)) { wasLoaded = true; } //------------------------------------------------------------ // Attempt to extract syndication information //------------------------------------------------------------ if (navigator.HasAttributes) { string hrefAttribute = navigator.GetAttribute("href", String.Empty); if (!String.IsNullOrEmpty(hrefAttribute)) { Uri href; if (Uri.TryCreate(hrefAttribute, UriKind.RelativeOrAbsolute, out href)) { this.Uri = href; wasLoaded = true; } } } if (navigator.HasChildren) { XPathNavigator titleNavigator = navigator.SelectSingleNode("atom:title", manager); XPathNodeIterator acceptIterator = navigator.Select("app:accept", manager); XPathNodeIterator categoriesIterator = navigator.Select("app:categories", manager); if (titleNavigator != null) { this.Title = new AtomTextConstruct(); if (this.Title.Load(titleNavigator)) { wasLoaded = true; } } if (acceptIterator != null && acceptIterator.Count > 0) { while (acceptIterator.MoveNext()) { AtomAcceptedMediaRange mediaRange = new AtomAcceptedMediaRange(); if (mediaRange.Load(acceptIterator.Current)) { this.Accepts.Add(mediaRange); wasLoaded = true; } } } if (categoriesIterator != null && categoriesIterator.Count > 0) { while (categoriesIterator.MoveNext()) { AtomCategoryDocument categories = new AtomCategoryDocument(); categories.Load(categoriesIterator.Current); wasLoaded = true; } } } return wasLoaded; }
/// <summary> /// Creates a new <see cref="AtomCategoryDocument"/> instance using the specified <see cref="Uri"/>, <see cref="ICredentials"/>, <see cref="IWebProxy"/>, and <see cref="SyndicationResourceLoadSettings"/> object. /// </summary> /// <param name="source">A <see cref="Uri"/> that represents the URL of the syndication resource XML data.</param> /// <param name="options">A <see cref="WebRequestOptions"/> that holds options that should be applied to web requests.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> object used to configure the <see cref="AtomCategoryDocument"/> instance. This value can be <b>null</b>.</param> /// <returns>An <see cref="AtomCategoryDocument"/> object loaded using the <paramref name="source"/> data.</returns> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="FormatException">The <paramref name="source"/> data does not conform to the expected syndication content format. In this case, the document remains empty.</exception> public static AtomCategoryDocument Create(Uri source, WebRequestOptions options, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ AtomCategoryDocument syndicationResource = new AtomCategoryDocument(); //------------------------------------------------------------ // Validate parameters //------------------------------------------------------------ Guard.ArgumentNotNull(source, "source"); //------------------------------------------------------------ // Create new instance using supplied parameters //------------------------------------------------------------ syndicationResource.Load(source, options, settings); return syndicationResource; }