diff --git a/src/Rss/RssElementNames.cs b/src/Rss/RssElementNames.cs index ef04a10..ac3f969 100644 --- a/src/Rss/RssElementNames.cs +++ b/src/Rss/RssElementNames.cs @@ -11,6 +11,7 @@ namespace Microsoft.SyndicationFeed.Rss public static class RssElementNames { public const string Author = "author"; + public const string Body = "body"; public const string Category = "category"; public const string Channel = "channel"; public const string Cloud = "cloud"; diff --git a/src/Rss/RssParser.cs b/src/Rss/RssParser.cs index 4f9b0b7..5c8b334 100644 --- a/src/Rss/RssParser.cs +++ b/src/Rss/RssParser.cs @@ -379,10 +379,25 @@ private static ISyndicationContent ReadSyndicationContent(XmlReader reader) } reader.MoveToContent(); - } - - // - // Content + } + + // + // Body (special case to read XHTML bodies as a value) + if (reader.LocalName == RssElementNames.Body) + { + // Read the OuterXml to make sure the namespace is in scope for nested elements + content.Value = reader.ReadOuterXml(); + + // Trim the outer
element + int startIndex = content.Value.IndexOf('>') + 1; + int endIndex = content.Value.LastIndexOf('<'); + content.Value = content.Value.Substring(startIndex, endIndex - startIndex); + + return content; + } + + // + // Content if (!reader.IsEmptyElement) { reader.ReadStartElement(); diff --git a/tests/RssReader.cs b/tests/RssReader.cs index 6882d73..3b5f34f 100644 --- a/tests/RssReader.cs +++ b/tests/RssReader.cs @@ -164,6 +164,24 @@ private async Task ReadWhile() } } } + } + + [Fact] + private async Task ReadBody() + { + using (var xmlReader = XmlReader.Create(@"..\..\..\TestFeeds\RssWithBody.xml", new XmlReaderSettings() { Async = true })) + { + var reader = new RssFeedReader(xmlReader); + + ISyndicationItem item; + while (await reader.Read()) + { + if(reader.ElementType == SyndicationElementType.Item) + { + item = await reader.ReadItem(); + } + } + } } [Fact] diff --git a/tests/TestFeeds/RssWithBody.xml b/tests/TestFeeds/RssWithBody.xml new file mode 100644 index 0000000..9f5e50e --- /dev/null +++ b/tests/TestFeeds/RssWithBody.xml @@ -0,0 +1,28 @@ + ++ The fact that Azure also provides low-priority/lower-cost batch hosts is a nice bonus. +
+ +