i'm trying data xml file - see below.
basically each session data, elements in , store need movie_name elements reference movie.
<schedule_data> <movies> <movie> <cinema_id>3169101</cinema_id> <movie_id>1012689</movie_id> <movie_name>2d captain america: civil war</movie_name> <rating>pg13</rating> <runtime>160</runtime> </movie> <movie> <cinema_id>3169101</cinema_id> <movie_id>1012984</movie_id> <movie_name>2d zootopia</movie_name> <rating>pg</rating> <runtime>115</runtime> </movie> </movies> <sessions> <session> <cinema_id>8888888</cinema_id> <movie_id>1012689</movie_id> <session_id>1083592422</session_id> <price_group_code>10007</price_group_code> <auditorium_number>9</auditorium_number> <assigned_seating>true</assigned_seating> <attribute></attribute> <date_time>20160607141000</date_time> <total_seats>87</total_seats> <available_seats>87</available_seats> </session> <session> <cinema_id>8888888</cinema_id> <movie_id>1012984</movie_id> <session_id>1083592423</session_id> <price_group_code>10007</price_group_code> <auditorium_number>9</auditorium_number> </session> </sessions> </schedule_data>
currently code is:
xdocument thisxml = xdocument.parse(responsetext); //get dates element (which contains date nodes) xelement dateselement = thisxml.element("schedule_data").element("sessions"); //use linq compile ienumerable of date nodes var dates = datenode in dateselement.elements("session") select datenode; //get dates element (which contains film nodes) xelement movieselement = thisxml.element("schedule_data").element("movies"); foreach (xelement session in dates) { //get movie name var films = filmnode in movieselement.elements("movie") select filmnode; var movieid = session.element("movie_id").value; // try clause , try value returns null var answer = reply in films reply.element("movie_id").value == movieid select films.elements("movie_name"); //create new session import record orm.sessionimportattemptimportedsession newsessionimportattemptimportedsession = new orm.sessionimportattemptimportedsession(); //check data , set properties newsessionimportattemptimportedsession.movietitle = answer.tostring(); newsessionimportattemptimportedsession.screennumber = session.element("screen_bytnum").value; ..... numberofsessions++; }
any suggestions?
you're performing join between sessions , movies. this:
var query = s in doc.descendants("session") join m in doc.descendants("movie") on (string)s.element("movie_id") equals (string)m.element("movie_id") select new { moviename = (string)m.element("movie_name"), session = s, movie = m, };