chris carter's web log

Home |  Contact |  Admin
 

XElement, huh

Posted on November 19, 2008

I'm watching Anders' PDC 2008 presentation on the future of C# and right around minute 37 I noticed something cool.  He uses XElement to create a little xml fragment for the thing he was demonstrating.  Just to test it out I wrote this code:

IDictionary<string, int> members =
  new Dictionary<string, int>(){
  { "Chris", 38 },
  { "Anja", 37 },
  { "Riley", 4 },
  { "Emmitt", 2 }
};

XElement element = new XElement("Family",
  from m in members select new XElement(m.Key, m.Value));
Console.WriteLine(element.ToString());
1
2
3
4
5
6
7
8
9
10
11

Which outputs this:

Kinda cool, I've never used XElement before today but it's nice to know you can generate xml very easy using this(without having to create a dom).

Here's my code.

Comments

Post a Comment

(required)
(required)
(no HTML!)