Is there a way to create SyndicationFeed from String?

I am trying to recreate a SyndicationFeed (System.ServiceModel.Syndication) object from XML data that has been saved locally.

If I was working with XMLDocument it would be easy. I called LoadXml (string).

SyndicationFeed will only be loaded from XMLReader. XMLReader will only use Stream or another XMLReader or TextReader.

Since XMLDocument will load the string, I tried to do it like this (in the form of an 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 seem to get this to work. The stream is always empty, even if the XMLDocument is full of Feed, which will be loaded into the SyndicationFeed.

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

Thanks, Roberto

+2


a source to share


1 answer


Since StringReader extends TextReader this should work:



TextReader tr = new StringReader(xmlString);
XmlReader xmlReader = XmlReader.Create(tr);
SyndicationFeed feed = SyndicationFeed.Load(xmlReader);

      

+6


a source







All Articles