Convert XML attributes to a Dictionary in Linq to XML

Posted by NateD on Stack Overflow See other posts from Stack Overflow or by NateD
Published on 2010-04-08T16:59:43Z Indexed on 2010/04/08 17:03 UTC
Read the original article Hit count: 452

Filed under:
|

I've got a program that needs to convert two attributes of a particular tag to the key and value of an Dictionary<int,string>. The XML looks like this:

(fragment)

<startingPoint coordinates="1,1" player="1" />

and so far my LINQ looks something like this:

XNamespace ns = "http://the_namespace";
var startingpoints = from sp in xml.Elements(ns+"startingPoint")
                 from el in sp.Attributes()
                 select el.Value;

Which gets me a nice IEnumerable full of things like "1,1" and "1", but there should be a way to adapt something like this answer to do attributes instead of elements. Little help please? Thank you!

© Stack Overflow or respective owner

Related posts about c#

Related posts about linq-to-xml