Active Directory Products
Calls To Calendar
SMS To CSV
SMS To Gmail
Voicemail To Gmail
How Long For Me
<< Back To All Blogs
Enumerating all attributes of an element and adding them to a dictionary using LINQ with Lambda Expressions
Thursday, May 14th, 2009
I have been confronted a number of times lately with the need to record all attributes of an XML element, especially when working with SharePoint XML where the attributes are simply too many to strongly-type
the resulting output.
This can be easily achieved while using LINQ along with a simple Lambda expression.
Without further ado, here is my resolution:
var lists = from list in doc.Descendants("MyElement")
Attributes = (from attribute in list.Attributes()
n => n.Name.LocalName, n => n.Value)
This will give you a resulting var of elements' XML attributes. This can than be enumerated like any other C# dictionary.
Very useful, and not very hard, but took me a few minutes to figure out nonetheless.
LINQin' Tom Out.
Creating an Organizational Chart using C#: Part 1
ASP.NET Best Practices
Using MOSS and WSS SharePoint Workflow to Resize Images in an Image Library
Retrieving data from SharePoint SOAP Requests using LINQ
Programatically Retrieving an Assembly's PublicKeyToken through a PowerShell CmdLet
Currently no comments.
Add A Comment
Email Address: (not public, used to send notifications on further comments)
Enter the text above, except for the 1st and last character: