Parsing Elements in Second Nesting Level of XML File

naomidragon

New Member
I am working on a little executable application. The application is simply an XML Parser that will parse an XML file and store the data parsed into a Database. So the XML file that this application will do its magic on has the following structure:\[code\]<?xml version="1.0" encoding="utf-8"?><events> <event> <book>Felicity Fly</book> <author>Christina Gabbitas</author> <bookImgUrl>http://www.whsmith.co.uk/Images/Products\957\255\9780957255203_t_f.jpg</bookImgUrl> <info>Christina Gabbitas will be signing copies of her new book, Felicity Fly. Books should be bought from WHSmith. Proof of purchase may be necessary</info> <date>25 May 2013</date> <startTime>10:30</startTime> <location> <name>WHSmith Brent Cross</name> <address>Brent Cross Shopping Centre</address> <city>London</city> <county/> <postcode>NW4 3FB</postcode> <tel>020 8202 4226</tel> </location> </event> <!-- many more events as above here --></events>\[/code\]And here is what I have so far in terms of code parsing logic.\[code\]namespace XMLParser{ public class Parser { static void Main(string[] args) { var path_to_xml = "data.xml"; var xdoc = XDocument.Load(path_to_xml); var events = from e in xdoc.Descendants("event") select new { Book = (string)e.Element("book").Value, Author = (string)e.Element("author").Value, BookImgUrl = (string)e.Element("bookImgUrl").Value, Info = (string)e.Element("info").Value, Date = (string)e.Element("date").Value, Time = (string)e.Element("startTime").Value, // stuck here } } }}\[/code\]I get stuck where I get to the Location node, I don't know how to parse the location related information.Any help would be greatly appreciated.Thank You.
 
Back
Top