/// <summary> /// Loads this <see cref="ApmlProfile"/> using the supplied <see cref="XPathNavigator"/> and <see cref="SyndicationResourceLoadSettings"/>. /// </summary> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the load operation.</param> /// <returns><b>true</b> if the <see cref="ApmlProfile"/> 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="ApmlProfile"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception> public bool Load(XPathNavigator source, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ bool wasLoaded = false; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(settings, "settings"); //------------------------------------------------------------ // Initialize XML namespace resolver //------------------------------------------------------------ XmlNamespaceManager manager = ApmlUtility.CreateNamespaceManager(source.NameTable); //------------------------------------------------------------ // Attempt to extract syndication information //------------------------------------------------------------ if (source.HasAttributes) { string nameAttribute = source.GetAttribute("name", String.Empty); if (!String.IsNullOrEmpty(nameAttribute)) { this.Name = nameAttribute; wasLoaded = true; } } if(source.HasChildren) { XPathNavigator implicitDataNavigator = source.SelectSingleNode("apml:ImplicitData", manager); XPathNavigator explicitDataNavigator = source.SelectSingleNode("apml:ExplicitData", manager); if (implicitDataNavigator != null) { XPathNodeIterator conceptsIterator = implicitDataNavigator.Select("apml:Concepts/apml:Concept", manager); if (conceptsIterator != null && conceptsIterator.Count > 0) { while (conceptsIterator.MoveNext()) { ApmlConcept concept = new ApmlConcept(); if (concept.Load(conceptsIterator.Current, settings)) { this.ImplicitConcepts.Add(concept); wasLoaded = true; } } } XPathNodeIterator sourcesIterator = implicitDataNavigator.Select("apml:Sources/apml:Source", manager); if (sourcesIterator != null && sourcesIterator.Count > 0) { while (sourcesIterator.MoveNext()) { ApmlSource attentionSource = new ApmlSource(); if (attentionSource.Load(sourcesIterator.Current, settings)) { this.ImplicitSources.Add(attentionSource); wasLoaded = true; } } } } if (explicitDataNavigator != null) { XPathNodeIterator conceptsIterator = explicitDataNavigator.Select("apml:Concepts/apml:Concept", manager); if (conceptsIterator != null && conceptsIterator.Count > 0) { while (conceptsIterator.MoveNext()) { ApmlConcept concept = new ApmlConcept(); if (concept.Load(conceptsIterator.Current, settings)) { this.ExplicitConcepts.Add(concept); wasLoaded = true; } } } XPathNodeIterator sourcesIterator = explicitDataNavigator.Select("apml:Sources/apml:Source", manager); if (sourcesIterator != null && sourcesIterator.Count > 0) { while (sourcesIterator.MoveNext()) { ApmlSource attentionSource = new ApmlSource(); if (attentionSource.Load(sourcesIterator.Current, settings)) { this.ExplicitSources.Add(attentionSource); wasLoaded = true; } } } } } //------------------------------------------------------------ // Attempt to extract syndication extension information //------------------------------------------------------------ SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(source, settings); adapter.Fill(this); return wasLoaded; }
/// <summary> /// Loads this <see cref="ApmlProfile"/> using the supplied <see cref="XPathNavigator"/> and <see cref="SyndicationResourceLoadSettings"/>. /// </summary> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the load operation.</param> /// <returns><b>true</b> if the <see cref="ApmlProfile"/> 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="ApmlProfile"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception> public bool Load(XPathNavigator source, SyndicationResourceLoadSettings settings) { bool wasLoaded = false; Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(settings, "settings"); XmlNamespaceManager manager = ApmlUtility.CreateNamespaceManager(source.NameTable); if (source.HasAttributes) { string nameAttribute = source.GetAttribute("name", String.Empty); if (!String.IsNullOrEmpty(nameAttribute)) { this.Name = nameAttribute; wasLoaded = true; } } if (source.HasChildren) { XPathNavigator implicitDataNavigator = source.SelectSingleNode("apml:ImplicitData", manager); XPathNavigator explicitDataNavigator = source.SelectSingleNode("apml:ExplicitData", manager); if (implicitDataNavigator != null) { XPathNodeIterator conceptsIterator = implicitDataNavigator.Select("apml:Concepts/apml:Concept", manager); if (conceptsIterator != null && conceptsIterator.Count > 0) { while (conceptsIterator.MoveNext()) { ApmlConcept concept = new ApmlConcept(); if (concept.Load(conceptsIterator.Current, settings)) { this.ImplicitConcepts.Add(concept); wasLoaded = true; } } } XPathNodeIterator sourcesIterator = implicitDataNavigator.Select("apml:Sources/apml:Source", manager); if (sourcesIterator != null && sourcesIterator.Count > 0) { while (sourcesIterator.MoveNext()) { ApmlSource attentionSource = new ApmlSource(); if (attentionSource.Load(sourcesIterator.Current, settings)) { this.ImplicitSources.Add(attentionSource); wasLoaded = true; } } } } if (explicitDataNavigator != null) { XPathNodeIterator conceptsIterator = explicitDataNavigator.Select("apml:Concepts/apml:Concept", manager); if (conceptsIterator != null && conceptsIterator.Count > 0) { while (conceptsIterator.MoveNext()) { ApmlConcept concept = new ApmlConcept(); if (concept.Load(conceptsIterator.Current, settings)) { this.ExplicitConcepts.Add(concept); wasLoaded = true; } } } XPathNodeIterator sourcesIterator = explicitDataNavigator.Select("apml:Sources/apml:Source", manager); if (sourcesIterator != null && sourcesIterator.Count > 0) { while (sourcesIterator.MoveNext()) { ApmlSource attentionSource = new ApmlSource(); if (attentionSource.Load(sourcesIterator.Current, settings)) { this.ExplicitSources.Add(attentionSource); wasLoaded = true; } } } } } SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(source, settings); adapter.Fill(this); return(wasLoaded); }
//============================================================ // PUBLIC METHODS //============================================================ #region Load(XPathNavigator source) /// <summary> /// Loads this <see cref="ApmlProfile"/> 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="ApmlProfile"/> 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="ApmlProfile"/>. /// </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"); //------------------------------------------------------------ // Initialize XML namespace resolver //------------------------------------------------------------ XmlNamespaceManager manager = ApmlUtility.CreateNamespaceManager(source.NameTable); //------------------------------------------------------------ // Attempt to extract syndication information //------------------------------------------------------------ if (source.HasAttributes) { string nameAttribute = source.GetAttribute("name", String.Empty); if (!String.IsNullOrEmpty(nameAttribute)) { this.Name = nameAttribute; wasLoaded = true; } } if (source.HasChildren) { XPathNavigator implicitDataNavigator = source.SelectSingleNode("apml:ImplicitData", manager); XPathNavigator explicitDataNavigator = source.SelectSingleNode("apml:ExplicitData", manager); if (implicitDataNavigator != null) { XPathNodeIterator conceptsIterator = implicitDataNavigator.Select("apml:Concepts/apml:Concept", manager); if (conceptsIterator != null && conceptsIterator.Count > 0) { while (conceptsIterator.MoveNext()) { ApmlConcept concept = new ApmlConcept(); if (concept.Load(conceptsIterator.Current)) { this.ImplicitConcepts.Add(concept); wasLoaded = true; } } } XPathNodeIterator sourcesIterator = implicitDataNavigator.Select("apml:Sources/apml:Source", manager); if (sourcesIterator != null && sourcesIterator.Count > 0) { while (sourcesIterator.MoveNext()) { ApmlSource attentionSource = new ApmlSource(); if (attentionSource.Load(sourcesIterator.Current)) { this.ImplicitSources.Add(attentionSource); wasLoaded = true; } } } } if (explicitDataNavigator != null) { XPathNodeIterator conceptsIterator = explicitDataNavigator.Select("apml:Concepts/apml:Concept", manager); if (conceptsIterator != null && conceptsIterator.Count > 0) { while (conceptsIterator.MoveNext()) { ApmlConcept concept = new ApmlConcept(); if (concept.Load(conceptsIterator.Current)) { this.ExplicitConcepts.Add(concept); wasLoaded = true; } } } XPathNodeIterator sourcesIterator = explicitDataNavigator.Select("apml:Sources/apml:Source", manager); if (sourcesIterator != null && sourcesIterator.Count > 0) { while (sourcesIterator.MoveNext()) { ApmlSource attentionSource = new ApmlSource(); if (attentionSource.Load(sourcesIterator.Current)) { this.ExplicitSources.Add(attentionSource); wasLoaded = true; } } } } } return(wasLoaded); }