locked
Loading Xml from memory in WinRT RRS feed

  • Question

  • I´m practicing doing common task with WinRT, just to learn the platform. I was trying to populate a SyndicationFeed class from and XmlDocument:

     

    SyndicationFeed feed = new SyndicationFeed();
                
    feed.LoadFromXml(xml);
    

     

    So, the parameter that gets passed to LoadFromXml must be an XmlDocument (WinRT one). My xml data comes from a custom service that gives me an Stream. Given I need to load it from memory, I was expecting a method in XmlDocument class that would accept an IInputStream as parameter.

    Unfurtunately it's not, XmlDocument only has overloads for loading from file or string sources.

    This was very easy when using XLinq:

    MemoryStream stream = GetXmlStreamFromService();
    
    var xml = XDocument.Load(stream);
    

    Is there a way to handle this scenario in WinRT?

     


    • Edited by iCeCLoW Friday, September 23, 2011 11:57 PM
    Friday, September 23, 2011 11:56 PM

Answers

All replies

  • var sr = new System.IO.StreamReader(stream);
    var myStr
    = sr.ReadToEnd();

    Should allow you to load your Stream in a String and then use that String as the parameter for your XmlDocument.
    Saturday, September 24, 2011 11:56 AM
  • Well, that was not what I expected. 

    This is like going back to years ago. I cannot believe that loading a Stream, reading it to the end, and then fill the XmlDocument structure can be the most perfomant way of doing things, in the end that is why XmlReader accepts a stream.

    I think should make in the final WinRT release, can be as easy as acception an WinRT input stream instead of only FileInput one.

     

    Saturday, September 24, 2011 10:50 PM
  • Right, today WinRT XML doesn't have streaming API aka XmlReader/XmlWriter. In this case, you can leverage DataReader to get the Unicode string out and then pass to XmlDocument with LoadXml.
    Tuesday, March 13, 2012 7:08 AM