XML-элементы в C # Windows Phone 7 - PullRequest
1 голос
/ 07 марта 2012

Привет, все уже давно застряли на этом, не очень уверен, куда идти отсюда.

У меня есть этот xml

<movies>
  <movie>
    <score/>
    <popularity>3</popularity>
    <translated>true</translated>
    <adult>false</adult>
    <language>en</language>
    <original_name>Batman</original_name>
    <name>Batman</name>
    <alternative_name>Batman (1989)</alternative_name>
    <type>movie</type>
    <id>268</id>
    <imdb_id>tt0096895</imdb_id>
    <url>http://www.themoviedb.org/movie/268</url>
    <votes>29</votes>
    <rating>8.1</rating>
    <certification>PG-13</certification>
    <overview>Gotham City: dark, dangerous, 'protected' only by a mostly corrupt police department. Despite the best efforts of D.A. Harvey Dent and police commissioner Jim Gordon, the city becomes increasingly unsafe...until a Dark Knight arises. Jack Napier, one-time enforcer for Boss Grissom, horribly disfigured after a firefight in a chemical factory...who, devoid of the last vestiges of sanity, seizes control of Gotham's underworld as the psychotic, unpredictable Clown Prince of Crime...the Joker.</overview>
    <released>1989-06-23</released>
    <images>
      <image type="poster" url="http://cf2.imgobject.com/t/p/w92/a84j66FTKvobDFdaPEQ7eAQzbWU.jpg" size="thumb" width="92" height="138" id="4ea5d2bca34d4b37d20005c3"/>
      <image type="poster" url="http://cf2.imgobject.com/t/p/w154/a84j66FTKvobDFdaPEQ7eAQzbWU.jpg" size="w154" width="154" height="231" id="4ea5d2bca34d4b37d20005c3"/>
      <image type="poster" url="http://cf2.imgobject.com/t/p/w185/a84j66FTKvobDFdaPEQ7eAQzbWU.jpg" size="cover" width="185" height="278" id="4ea5d2bca34d4b37d20005c3"/>
      <image type="poster" url="http://cf2.imgobject.com/t/p/w342/a84j66FTKvobDFdaPEQ7eAQzbWU.jpg" size="w342" width="342" height="513" id="4ea5d2bca34d4b37d20005c3"/>
      <image type="poster" url="http://cf2.imgobject.com/t/p/w500/a84j66FTKvobDFdaPEQ7eAQzbWU.jpg" size="mid" width="500" height="750" id="4ea5d2bca34d4b37d20005c3"/>
      <image type="poster" url="http://cf2.imgobject.com/t/p/original/a84j66FTKvobDFdaPEQ7eAQzbWU.jpg" size="original" width="1000" height="1500" id="4ea5d2bca34d4b37d20005c3"/>
      <image type="backdrop" url="http://cf2.imgobject.com/t/p/w300/qDNiKJ46kQ6LHo9eyBK8u2QwRpF.jpg" size="thumb" width="300" height="169" id="4ea5d2b0a34d4b37d20005b9"/>
      <image type="backdrop" url="http://cf2.imgobject.com/t/p/w780/qDNiKJ46kQ6LHo9eyBK8u2QwRpF.jpg" size="poster" width="780" height="439" id="4ea5d2b0a34d4b37d20005b9"/>
      <image type="backdrop" url="http://cf2.imgobject.com/t/p/w1280/qDNiKJ46kQ6LHo9eyBK8u2QwRpF.jpg" size="w1280" width="1280" height="720" id="4ea5d2b0a34d4b37d20005b9"/>
      <image type="backdrop" url="http://cf2.imgobject.com/t/p/original/qDNiKJ46kQ6LHo9eyBK8u2QwRpF.jpg" size="original" width="1920" height="1080" id="4ea5d2b0a34d4b37d20005b9"/>
    </images>
    <version>1242</version>
    <last_modified_at>2012-03-05 19:39:45 UTC</last_modified_at>
  </movie>
</movies>

с использованием

       void movie_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
    {
        if (e.Error != null)
            return;
        XElement xmlMovie = XElement.Parse(e.Result);

        listBox1.ItemsSource = from movie in xmlMovie.Descendants("movies")
                               select new MovieItem
                               {
                                   FilmName = movie.Element("movie").Element("alternative_name").Value,
                                   overview = movie.Element("movie").Element("overview").Value,
                                   rating = movie.Element("movie").Element("rating").Value,
                                   filmurl = movie.Element("movie").Element("images").Element("image").Attribute("url").Value
                               };


        listBox2.ItemsSource = from movie in xmlMovie.Descendants("movies")
                               //  where movie.Element("movie").Element("images").Element("image").Attribute("size").Value == "cover"
                               select new MovieItem
                               {
                                   rating = movie.Element("movie").Element("rating").Value
                               };

        var urls = xmlMovie
            .Descendants("image")
            .Where(x => x.Attribute("size").Value == "cover")
            .Select(x => x.Attribute("url").Value)
            .ToArray();

    }

    public class MovieItem
    {
        public string FilmName { get; set; }
        public string overview { get; set; }
        public string Poster { get; set; }
        public string rating { get; set; }
        public string filmurl { get; set; }
    }
}

}

теперь я могу получить URL-адрес с помощью оператора select и правильно его отобразить, но как мне получить URL-адрес для изображения с size = "cover"

довольно новымПри всем этом пытаться учиться, как я иду один, поэтому любая помощь будет велика: D

спасибо

1 Ответ

0 голосов
/ 07 марта 2012
var urls =  xmlMovie
    .Descendants("image")
    .Where(x=>x.Attribute("size").Value=="cover")
    .Select(x=>x.Attribute("url").Value)
    .ToArray();
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...