Hi, How to parse xml with descendants within descendants C#

qagertez

New Member
I am trying to parse this xml and can successfully get the name and description but putting together the image is tricky. Both separate code parses work but I'd like to do one parse so I can bind them all to one listbox.The xml looks like this\[code\]<stickers> <sticker> <imageData> <baseImageUrl> ... want this </baseImageUrl> <sizes> <size> don't care about this </size> </size> <imageUrlSuffix> ..want this </imageUrlSuffix> </imageData> <description>.... want this </description> <name> --want this </name> <sticker><stickers>\[/code\]My code works for both but separately. How do I combine this into one parse...\[code\]XDocument streamFeed = XDocument.Load(new StringReader(response.Content));var imagedata = http://stackoverflow.com/questions/11496570/from query in streamFeed.Descendants("sticker").Elements("imageData") select new Stickers { image = (string)query.Element("baseImageUrl") + "huge" + (string)query.Element("imageUrlSuffix"), };var data = http://stackoverflow.com/questions/11496570/from query in streamFeed.Descendants("sticker") select new Stickers { name = (string)query.Element("name"), description = (string)query.Element("description"), };stickersListBox.ItemsSource = imagedata.Union(data);\[/code\]The data displays in the listbox but with the stickers above the description and not side by side.ThanksThanks to Thomas below, the following code works but some user profiles get a Null Referenced Exception (including my own profile which obviously has data) Thanks Thoamas for the assistance perhaps this is an unrelated bug? \[code\]XDocument streamFeed = XDocument.Load(new StringReader(response.Content)); var query = from sticker in streamFeed.Root.Descendants("sticker") let imageData = http://stackoverflow.com/questions/11496570/sticker.Element("imageData") select new Stickers { name = (string)sticker.Element("name"), description = (string)sticker.Element("description"), image = (string)imageData.Element("baseImageUrl") + "huge" + (string)imageData.Element("imageUrlSuffix") }; stickersListBox.ItemsSource = query;\[/code\]
 
Back
Top