Easy XML Writing with C# 4.0 and DynamicBuilder


Easy XML Writing with C# 4.0 and DynamicBuilder

Feb, 10, 2011

Utilizing C# 4.0's 'dynamic' keyword, Michael Monteleone has created a "suspiciously pleasant XML construction API". Very easy to use and light weight makes this a new go to tool for me. The only part of it I found lacking (which he also clearly states he knows about in his documentation) is namespace support.

If you are building XML with C# check out this tool. https://github.com/mmonteleone/dynamicbuilder.

Straight from the documentation:

dynamic xml = new DynamicBuilder.Xml();

// passing an anonymous delegate creates a nested context
xml.user(Xml.Fragment(u => {
u.firstname("John");
u.lastname("Doe");
u.email("jdoe@example.org");
}));

// yields...
<user>
<firstname>John</firstname>
<lastname>Doe</lastname>
<email>jdoe@example.org</email>
</user>

Tags: C#, XML, Library

Contact

Recent Posts

Entity Framework update-database "Could not load file or assembly or one of its dependencies. The system cannot find the file specified."

I spun wheel for a while on this one. Every time I ran the update-database or add-migration command I was getting "Could not load file or assembly 'MyProject.Name' or one of its dependencies. The... Read More

You get nahzing, Lebowski!

Windows 8 CP to Windows 8 RP doesn't give you many choices on what I get to keep when I upgrade. Guess I won't be needing that "Help me decide" link.... Read More

 
@nickspiers