XML Fluid Value
What It Is
A Fluid value to query an XML document in a templateStatus
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:
An
XmlValue
represents a complete fragment of XML, with a single root node (people
at the start of the document, andperson
inside the loop iteration)A normal accessor will descend into the XML structure element by element. So
person.name.last
drills down through the elements with those names (from whatever the root is). Each time, it’s returning anotherXmlValue
._text
will return the text of the element as aStringValue
_attrs
will return aDictionaryValue
of the attributes of the element, so the next member will effectively access that key of the dictionary, or that attribute name_children
will return anArrayValue
ofXmlValues
representing the children of the node
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.