locked
Deserializing xml <feed xmlns='http://www.w3.org/2005/Atom'> was not expected. RRS feed

  • Question

  • Hello iam tring to deserialize a xml which I pull from youtube api(standerd feed:- https://developers.google.com/youtube/2.0/reference#Standard_feeds)

    I can serialize one object but not the list of objects, I got following error

    An exception of type 'System.InvalidOperationException' occurred in mscorlib.dll but was not handled in user code

    Additional information: There is an error in XML document (1, 40).

    inner exception

    <feed xmlns='http://www.w3.org/2005/Atom'> was not expected.

     I am posting the sample app here

    http://sdrv.ms/1hTSBgZ

    it have two method

    1. workingmethod()

    2. notworkingmethod()

    run the app after commenting one at a time in getdata button click event.

    pleaserun the app and press getdata button on UI


    Santana George



    Tuesday, November 19, 2013 7:47 AM

Answers

  • Hello,

    The <feed> that is returned by the server contains three <entry> nodes rather than three <feed> items. So although you are getting back 3 entries back, you only have one feed object, not a List of <feed> objects.

    I was able to get it working by changing the FeedItem.cs file, and changing the following fields (there are a few additions and a couple of deletions - commented out below). There are also some other changes required in your FeedItem.cs file such as changing byte, short, uint to int. Otherwise serialization errors are thrown. Hopefully it will resolve the issue for you.

        public partial class feed {
            ...
            private feedEntry[] entryField;
            ...
            public feedEntry[] entry {
            ...
            }
    
        public partial class feedEntry
        {
            ...
            [System.Xml.Serialization.XmlAttributeAttribute()]
            public string id
            
            [System.Xml.Serialization.XmlAttributeAttribute()]
            public System.DateTime published
    
            [System.Xml.Serialization.XmlAttributeAttribute()]
            public System.DateTime updated
    
            //[System.Xml.Serialization.XmlElementAttribute("category")]
            public feedEntryCategory[] category
    
            //[System.Xml.Serialization.XmlElementAttribute("link")]
            public feedEntryLink[] link
    


    Windows Store Developer Solutions, follow us on Twitter: @WSDevSol|| Want more solutions? See our blog

    • Marked as answer by Santana George Wednesday, November 20, 2013 3:03 AM
    Tuesday, November 19, 2013 11:24 PM
    Moderator