Skip to content
This repository was archived by the owner on Dec 15, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Rss/RssElementNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
23 changes: 19 additions & 4 deletions src/Rss/RssParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <body> 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();
Expand Down
18 changes: 18 additions & 0 deletions tests/RssReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
28 changes: 28 additions & 0 deletions tests/TestFeeds/RssWithBody.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:a10="http://www.w3.org/2005/Atom" version="2.0">
<channel xml:base="http://mypage.com/">
<title>Microsoft News</title>
<link>http://www.microsoft.com/news</link>
<category>My new category</category>
<description>&lt;div&gt;Most recent news from Microsoft&lt;/div&gt;</description>
<managingEditor>jerry@microsoft.com</managingEditor>
<lastBuildDate>Mon, 19 Jun 2017 11:52:39 -0700</lastBuildDate>
<image>
<url>http://2.bp.blogspot.com/-NA5Jb-64eUg/URx8CSdcj_I/AAAAAAAAAUo/eCx0irI0rq0/s1600/bg_Microsoft_logo3-20120824073001907469-620x349.jpg</url>
<title>Microsoft News</title>
<link>http://www.microsoft.com/news</link>
</image>
<a10:id>123FeedID</a10:id>
<customElement>asd</customElement>
<item>
<link>http://microsoft.com/news/path</link>
<title>SyndicationFeed released for .net Core</title>
<description>A lot of text describing the release of .net core feature</description>
<body xmlns="http://www.w3.org/1999/xhtml">
<p>
The fact that <a href="foobar">Azure also provides low-priority/lower-cost batch hosts</a> is a nice bonus.
</p>
</body>
</item>
</channel>
</rss>