Is there a way to create a SyndicationFeed from a String?

Posted by Roberto Bonini on Stack Overflow See other posts from Stack Overflow or by Roberto Bonini
Published on 2010-04-21T21:01:05Z Indexed on 2010/04/21 21:03 UTC
Read the original article Hit count: 378

Filed under:
|
|
|

Hi, I'm trying to recreate a SyndicationFeed object (System.ServiceModel.Syndication) from XML data that has been stored locally.

If I were working with XMLDocument, this would be easy.I'd call LoadXml(string).

The SyndicationFeed will only load from an XMLReader. The XMLReader will only take a Stream or another XMLReader or a TextReader.

Since XMLDocument will load a string, I've tried to do this as follows (in the form of a Extension Method):

    public static SyndicationFeed ToSyndicationFeed(this XmlDocument document)
    {
        Stream thestream = Stream.Null;
        XmlWriter thewriter = XmlWriter.Create(thestream);

        document.WriteTo(thewriter);

        thewriter.Flush();
        XmlReader thereader = XmlReader.Create(thestream);

        SyndicationFeed thefeed = SyndicationFeed.Load(thereader);

        return thefeed;
    }

I can't get this to work. The Stream is always empty even though the XMLDocument is populated with the Feed to be loaded into the SyndicationFeed.

Any help or pointers you can give would be most helpful.

Thanks, Roberto

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ