Beispiel #1
0
        public static bool TryParseRssAtom10Extension(XElement parentElement, out RssAtom10Extension extension)
        {
            extension = null;

            if (parentElement == null)
            {
                return(false);
            }

            foreach (var ns in RssAtom10ExtensionConstants.RecognizedNamespaces)
            {
                if (TryParseRssAtom10TextElement(parentElement.Element(ns + "id"), out var parsedId))
                {
                    extension    = extension ?? new RssAtom10Extension();
                    extension.Id = parsedId;
                }

                if (TryParseRssAtom10Timestamp(parentElement.Element(ns + "updated"), out var parsedUpdated))
                {
                    extension         = extension ?? new RssAtom10Extension();
                    extension.Updated = parsedUpdated;
                }

                foreach (var linkElement in parentElement.Elements(ns + "link"))
                {
                    if (TryParseRssAtom10Link(linkElement, out var parsedLink))
                    {
                        extension = extension ?? new RssAtom10Extension();
                        extension.Links.Add(parsedLink);
                    }
                }
            }

            return(extension != null);
        }
        public static bool TryFormatRssAtom10Extension(RssAtom10Extension extensionToFormat, XNamespaceAliasSet namespaceAliases, out IList <XElement> elements)
        {
            elements = default;

            if (extensionToFormat == null)
            {
                return(false);
            }

            elements = new List <XElement>();

            if (TryFormatRssAtom10TextElement(extensionToFormat.Id, "id", namespaceAliases, out var idElement))
            {
                elements.Add(idElement);
            }

            if (TryFormatRssAtom10Timestamp(extensionToFormat.Updated, "updated", namespaceAliases, out var updatedElement))
            {
                elements.Add(updatedElement);
            }

            foreach (var linkToFormat in extensionToFormat.Links ?? Enumerable.Empty <Atom10Link>())
            {
                if (TryFormatRssAtom10Link(linkToFormat, namespaceAliases, out var linkElement))
                {
                    elements.Add(linkElement);
                }
            }

            if (!elements.Any())
            {
                return(false);
            }

            return(true);
        }