XML data extracted across two classes



I have two classes and the following XML. I do not know how to create objects of Director and Movie out of the following XML. I'd like to use Linq but have tried many things and not sure.


I would like to have all director objects with their ID's and I'd like to have all the movie objects with all their fields.



public class Director
{
public int DirectorID;
public string Name;
}

public class Movie
{
public string DirectorID;
public string Genre;
public string Rating;
public string MovieName;
}



<?xml version="1.0" encoding="UTF-8"?>
<Movie xmlns="http://www.imdb.co.uk" CreationDate="2015-01-25T18:14:33" year="2012" NumberOfMovies="6">
<DirectorMovie>
<Director>
<Name>Ridley Scott</Name>
</Director>
<Movie>
<Genre>Horror</Genre>
<Rating>8.9</Rating>
<MovieName>Alien</MovieName>
</Movie>
<Movie>
<Genre>Sci-Fi</Genre>
<Rating>8.7</Rating>
<MovieName>Blade Runner</MovieName>
</Movie>
<Movie>
<Genre>Action</Genre>
<Rating>7.4</Rating>
<MovieName>Black Hawk Down</MovieName>
</Movie>
</DirectorMovie>
<DirectorMovie>
<Director>
<Name>James Cameron</Name>
</Director>
<Movie>
<Genre>Action</Genre>
<Rating>8.9</Rating>
<MovieName>Aliens</MovieName>
</Movie>
<Movie>
<Genre>Sci-Fi</Genre>
<Rating>8.5</Rating>
<MovieName>Avatar</MovieName>
</Movie>
<Movie>
<Genre>Action</Genre>
<Rating>8.8</Rating>
<MovieName>Prometheus</MovieName>
</Movie>
</DirectorMovie>
</Movie>

No comments:

Post a Comment