LINQ to XML Question

Getting Subnode values

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 6642 Views - Last Post: 13 November 2009 - 08:51 AM Rate Topic: -----

#16 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2247
  • View blog
  • Posts: 9,237
  • Joined: 18-February 07

Re: LINQ to XML Question

Posted 13 November 2009 - 08:51 AM

Well I used your example for simple queries but for exacting the larger object which had a number of different values I needed to extract I ended up reverting back to the other scheme, though I did simplify it slightly to:

var resultsVar = from di in resultsDoc.Descendants("result")
                 let items = di.Elements("item")
                 select new {
                    ColumnName = (
                        from item in items 
                        where "COLL_NAME".Equals(item.Element("name").Value) 
                        select item.Element("value").Value).First(),
                    Description = (
                        from item in items 
                        where "DESCRIPTION".Equals(item.Element("name").Value) 
                        select item.Element("value").Value).First()
                 };


(I am also not using the anonymous type -- rather I am actually populating object fields).

I have not done too much testing on performance but it seems to be reasonable.

Thank you both for your help. LINQ is slowly begining to make sense to me, and while am still a little frustrated with it (the syntax can be rather irritating in VS because of its indention rules) I am beginning to see how it can be used effectively.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2