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?

2
  • try the way explained in this answer: stackoverflow.com/questions/4203540/… Commented Jul 11, 2016 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 Commented Jul 11, 2016 at 15:14

1 Answer 1

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; }
        }
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.