Convert XML to a list of something

Reject7

New Member
I have a xml file coming from my php site as an api.This is the xml that is coming back from my php application.\[code\]<xml><overzicht><item><sessieID>6</sessieID><onderwerp>Vrijwilligers, een uitstervend rasnn</onderwerp><omschrijving>Ode aan de vrijwilligers jjj</omschrijving><sprekerID>1</sprekerID><lokaalID>20</lokaalID><themaID>1</themaID><typeID>2</typeID><periodeID>2</periodeID><datum>2012-02-20</datum><maximaleInschrijvingen>1</maximaleInschrijvingen><spreker> <sprekerID>1</sprekerID> <sprekerNaam>Rik Torfs</sprekerNaam> <loginID>13</loginID></spreker><lokaal> <lokaalID>20</lokaalID> <campusNaam>Malle</campusNaam> <lokaalOpCampus>W10</lokaalOpCampus> <typeID>2</typeID></lokaal></item><item><sessieID>15</sessieID><onderwerp>VPKB</onderwerp><omschrijving/><sprekerID>6</sprekerID><lokaalID>2</lokaalID><themaID>1</themaID><typeID>1</typeID><periodeID>2</periodeID><datum>2012-02-20</datum><maximaleInschrijvingen>50</maximaleInschrijvingen><spreker> <sprekerID>6</sprekerID> <sprekerNaam>Dick Wursten</sprekerNaam> <loginID>18</loginID></spreker><lokaal> <lokaalID>2</lokaalID> <campusNaam>KHK Vorselaar</campusNaam> <lokaalOpCampus>A102</lokaalOpCampus> <typeID>1</typeID></lokaal></item>...</overzicht></xml>\[/code\]This is my C# code. I want to get al list of Sessie.\[code\]XDocument xmlDoc = XDocument.Parse(e.Result);List<Sessie> sessies = ( from item in xmlDoc.Descendants("overzicht") select new Sessie( item.Element("onderwerp").Value, Convert.ToInt32(item.Element("sessieID").Value), item.Element("omschrijving").Value, (Spreker)( new Spreker( Convert.ToInt32(item.Element("spreker").Element("sprekerID").Value), item.Element("spreker").Element("sprekernaam").Value) ), Convert.ToDateTime(item.Element("datum").Value), Convert.ToInt32(item.Element("maximaleInschrijvingen").Value), (Lokaal)( new Lokaal( Convert.ToInt32(item.Element("lokaal").Element("lokaalID").Value), item.Element("lokaal").Element("campusNaam").Value, item.Element("lokaal").Element("lokaalOpCampus").Value) ) ) ).ToList<Sessie>();\[/code\]I know my code isn't working with this exception."NullReferenceException"
 
Back
Top