コード例 #1
0
        /// <summary>
        /// Initializes the syndication extension context optional elements using the supplied <see cref="XPathNavigator"/>.
        /// </summary>
        /// <param name="source">The <b>XPathNavigator</b> used to load this <see cref="DublinCoreElementSetSyndicationExtensionContext"/>.</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="DublinCoreElementSetSyndicationExtensionContext"/> 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 LoadOptionals(XPathNavigator source, XmlNamespaceManager manager)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            bool wasLoaded = false;

            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(source, "source");
            Guard.ArgumentNotNull(manager, "manager");

            //------------------------------------------------------------
            //	Attempt to extract syndication extension information
            //------------------------------------------------------------
            XPathNavigator coverageNavigator   = source.SelectSingleNode("dc:coverage", manager);
            XPathNavigator formatNavigator     = source.SelectSingleNode("dc:format", manager);
            XPathNavigator identifierNavigator = source.SelectSingleNode("dc:identifier", manager);
            XPathNavigator relationNavigator   = source.SelectSingleNode("dc:relation", manager);
            XPathNavigator sourceNavigator     = source.SelectSingleNode("dc:source", manager);
            XPathNavigator subjectNavigator    = source.SelectSingleNode("dc:subject", manager);
            XPathNavigator typeNavigator       = source.SelectSingleNode("dc:type", manager);

            if (coverageNavigator != null && !String.IsNullOrEmpty(coverageNavigator.Value))
            {
                this.Coverage = coverageNavigator.Value;
                wasLoaded     = true;
            }

            if (formatNavigator != null && !String.IsNullOrEmpty(formatNavigator.Value))
            {
                this.Format = formatNavigator.Value;
                wasLoaded   = true;
            }

            if (identifierNavigator != null && !String.IsNullOrEmpty(identifierNavigator.Value))
            {
                this.Identifier = identifierNavigator.Value;
                wasLoaded       = true;
            }

            if (relationNavigator != null && !String.IsNullOrEmpty(relationNavigator.Value))
            {
                this.Relation = relationNavigator.Value;
                wasLoaded     = true;
            }

            if (sourceNavigator != null && !String.IsNullOrEmpty(sourceNavigator.Value))
            {
                this.Source = sourceNavigator.Value;
                wasLoaded   = true;
            }

            if (subjectNavigator != null && !String.IsNullOrEmpty(subjectNavigator.Value))
            {
                this.Subject = subjectNavigator.Value;
                wasLoaded    = true;
            }

            if (typeNavigator != null && !String.IsNullOrEmpty(typeNavigator.Value))
            {
                DublinCoreTypeVocabularies typeVocabulary = DublinCoreElementSetSyndicationExtension.TypeVocabularyByName(typeNavigator.Value);
                if (typeVocabulary != DublinCoreTypeVocabularies.None)
                {
                    this.TypeVocabulary = typeVocabulary;
                    wasLoaded           = true;
                }
            }

            return(wasLoaded);
        }