0

I've been trying to wrap my head around what's going wrong, but haven't been able to put my finger on it. Maybe you can see where I'm going wrong with deserialising this feed.

From the XML feed I have this structure:

<Recommendation>
  <screenshot-urls>          
    <screenshots d="320x480">
      <screenshot orientation="portrait" w="320" h="480">url1</screenshot>
      <screenshot orientation="portrait" w="320" h="480">url2</screenshot>
      <screenshot orientation="portrait" w="320" h="480">url3</screenshot>
      <screenshot orientation="portrait" w="320" h="480">url4</screenshot>
    </screenshots>
    <screenshots d="480x800">
      <screenshot orientation="portrait" w="480" h="800">url1</screenshot>
      <screenshot orientation="portrait" w="480" h="800">url2</screenshot>
      <screenshot orientation="portrait" w="480" h="800">url3</screenshot>
      <screenshot orientation="portrait" w="480" h="800">url4</screenshot>
    </screenshots>
  </screenshot-urls>
</recommendation>

I've got the following code lined up, I've tried all sorts of things but the closest I got was having an array of 4 screenshots that only used the url of the first screenshot.

public class Recommendation
{
    /// <remarks />
    [XmlElement("screenshot-urls")]
    public TopAppScreenshots[] screenshoturls { get; set; }

    public class TopAppScreenshots
    {
        public TopAppScreenshot[] Screenshots { get; set; }

        public class TopAppScreenshot
        {
            [XmlAttribute("w")]
            public string Width { get; set; }

            [XmlAttribute("h")]
            public string Height { get; set; }

            [XmlAttribute("orientation")]
            public string Orientation { get; set; }

            [XmlText]
            public string ScreenshotUrl { get; set; }
        }
    }
}

At the moment with this code the screenshots object is empty, but looking at other examples I really think this code should work. What am I doing wrong?

Flippey
  • 91
  • 1
  • 8
  • try the way explained in this answer: http://stackoverflow.com/questions/4203540/generate-c-sharp-class-from-xml – Abdullah Nehir Jul 11 '16 at 14:56
  • Good tip, didn't know about that paste special thing! It's really neat but it didn't work yet, will try some more things tomorrow to see if the feed isn't in the wrong format – Flippey Jul 11 '16 at 15:14

1 Answers1

1
public class Recommendation
{
    [XmlArray("screenshot-urls")]
    [XmlArrayItem("screenshots")]
    public TopAppScreenshots[] Screenshoturls { get; set; }

    public class TopAppScreenshots
    {
        [XmlElement("screenshot")]
        public TopAppScreenshot[] Screenshot { get; set; }

        [XmlAttribute("d")]
        public string Dimension { get; set; }

        public class TopAppScreenshot
        {
            [XmlAttribute("w")]
            public string Width { get; set; }

            [XmlAttribute("h")]
            public string Height { get; set; }

            [XmlAttribute("orientation")]
            public string Orientation { get; set; }

            [XmlText]
            public string ScreenshotUrl { get; set; }
        }
    }
}
Alexander Petrov
  • 13,457
  • 2
  • 20
  • 49
  • Thank you, this works perfectly :) I came so close too, I had the XMLArray annotation on hte screenshot urls but I had the arrayitem on the Screenshot object – Flippey Jul 12 '16 at 06:40