Fluent XML writer

Writing XML in .NET is not too terrible, but it sometimes is a bit tricky and lengthy.

A few years ago, I put this library together to write XML easily, using fluent techniques.

static void Main(string[] args) {
        .Simple("Second").Attr("a", "b")
                SimpleElement.Create("Arr1").Attr("key1", "val1"),
                SimpleElement.Create("Arr2").Attr("key2", "val2")
        .Complex("Third").Text("My Text").EndElem()
        .Complex("Fourth").CData("Hello there!").EndElem()
        .Comment("A comment!")

This produces the following output:

    <First />
    <Second a="b" />
        <Arr1 key1="val1" />
        <Arr2 key2="val2" />
    <Third>My Text</Third>
    <Fourth><![CDATA[Hello there!]]></Fourth>
    <!--A comment!-->
Download on Github


Popular posts from this blog

DotNet CLI

Switch Expressions