XML Fluid Value

Class Library
C#
GitHub Gist

What It Is

A Fluid value to query an XML document in a template

Status

Last Reviewed:

Written as a POC. Never did anything with it.

Details

This Fluid value allows you to push raw XML into Fluid template, extract values from it, and iterate elements in it.

Consider this XML:

<people>
    <person>
        <name prefix="Mr">
            <first>Deane</first>
            <last>Barker</last>
        </name>
    </person>
    <person>
        <name prefix="Mrs">
            <first>Annie</first>
            <last>Barker</last>
        </name>
    </person>
</people>
var xml = GetTheXml();
templateContext.SetValue("people", new XmlValue(xml));
{% for person in people._children %}
* {{ person.name._attrs.prefix }} {{ person.name.first._text }} {{ person.name.last._text }}
{% endfor %}

Everything available is documented above:

There is no functionality for descendents or ancestors or anything else, just children. However, with the functions capability of Fluid which was released after I wrote that, it would be fairly easy inject some type of XPath support.

This code is a good reference example for using GetValue to create virtual members.