c# - How do I nest this LINQ query? -


i have xml document web service trying query. however, not sure how query xml when has elements nested inside other elements.

here section of xml file (i haven't included of because it's long file):

<response>     <display_location>         <full>london, united kingdom</full>         <city>london</city>         <state/>         <state_name>united kingdom</state_name>         <country>uk</country>         <country_iso3166>gb</country_iso3166>         <zip>00000</zip>         <magic>553</magic>         <wmo>03772</wmo>         <latitude>51.47999954</latitude>         <longitude>-0.44999999</longitude>         <elevation>24.00000000</elevation>     </display_location>     <observation_location>         <full>london,</full>         <city>london</city>         <state/>         <country>uk</country>         <country_iso3166>gb</country_iso3166>         <latitude>51.47750092</latitude>         <longitude>-0.46138901</longitude>         <elevation>79 ft</elevation>     </observation_location> 

i can query "one section @ time" i'm constructing object linq. example:

var data = in weatherresponse.descendants("display_location")            select new forecast            {                displayfullname = i.element("full").value            };  var data = in weatherresponse.descendants("observation_location")            select new forecast            {                observationfullname = i.element("full").value            }; 

and "forecast" class full of properties this:

class forecast {     public string displayfullname { get; set; };     public string observationfullname { get; set; };     //lots of other properties set xml } 

however, need "combine" of linq can set properties of object. have read nested linq not know how apply particular case.

question: how go "nesting/combining" linq can read xml , set appropriate properties said xml?

one possible way :

var data = in weatherresponse.descendants("response")            select new forecast            {                displayfullname = (string)i.element("display_location").element("full"),                observationfullname = (string)i.element("observation_location").element("full")            }; 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -