Skip to content
This repository has been archived by the owner on Dec 15, 2021. It is now read-only.

Example writer code does not work - doesn't write closing tags #49

Open
Cloudmersive opened this issue Aug 24, 2020 · 2 comments
Open

Comments

@Cloudmersive
Copy link

Cloudmersive commented Aug 24, 2020

Example code on your readme:

var sw = new StringWriterWithEncoding(Encoding.UTF8);

using (XmlWriter xmlWriter = XmlWriter.Create(sw, new XmlWriterSettings() { Async = true, Indent = true }))
{
    var writer = new RssFeedWriter(xmlWriter);
      
    // Create item
    var item = new SyndicationItem()
    {
        Title = "Rss Writer Avaliable",
        Description = "The new Rss Writer is now available as a NuGet Package!",
        Id = "https://www.nuget.org/packages/Microsoft.SyndicationFeed.ReaderWriter",
        Published = DateTimeOffset.UtcNow
    };

    item.AddCategory(new SyndicationCategory("Technology"));
    item.AddContributor(new SyndicationPerson("test", "[email protected]"));

    await writer.Write(item);
    xmlWriter.Flush();
}

class StringWriterWithEncoding : StringWriter
{
    private readonly Encoding _encoding;

    public StringWriterWithEncoding(Encoding encoding)
    {
        this._encoding = encoding;
    }

    public override Encoding Encoding {
        get { return _encoding; }
    }
}

Actual output:

<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel><item>
  <title>Rss Writer Avaliable</title>
  <description>The new Rss Writer is now available as a NuGet Package!</description>
  <author>[email protected]</author>
  <category>Technology</category>
  <guid isPermaLink="false">https://www.nuget.org/packages/Microsoft.SyndicationFeed.ReaderWriter</guid>
  <pubDate>Mon, 24 Aug 2020 02:59:48 GMT</pubDate>
</item>

Notice how this is INVALID XML

@dominikdalek
Copy link

Can confirm this behavior.

@larsalmen
Copy link

Replacing the call to the synchronous xmlWriter.Flush() with it's async counterpart and awaiting it like so; await xmlWriter.FlushAsync() fixes this issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants