Getting Data as XML
EXPERIENCE MANAGEMENT > DATA
When you create a datatype in Experience Management, the system automatically generates a number of functions for it - the so-called “data-centric” functions.
One of the frequently used data-centric functions is the function that allows you to get data items of the datatype as an enumerable list of XML elements (XElements).
The function is placed within the namespace the datatype belongs to, and its name follows this pattern:
Get<DataType>XML
where <DataType> stands for the name of the datatype.
For example, if you create a datatype called Demo.Customers, Experience Management generates a function:
Demo.Customers.GetCustomersXml
You can call such a function from another function. When used as a function call in an XSLT function (with the local name of “GetCustomersXml”), it can be referred to in the markup as
/in:inputs/in:result[@name='GetCustomersXml']
Each data item retrieved with such a function is presented as an XML element:
<Customers Id="4ee4b37d-4388-4f15-a88b-bc8f1ada2b4c" Name="John Doe" Email="john.doe@somecompany.com" xmlns=""/>
In this element:
|
•
|
the name is that of the datatype (without namespaces) |
|
•
|
the attributes are the names of the fields in the datatype |
|
•
|
the attribute values are the values in the datatype fields |
You can thus iterate the data items by using XPath.
For example, having added a call to the function ‘GetCustomersXml’ as its local name to an XSLT function, you can iterate its data items as follows:
<xsl:for-each select="/in:inputs/in:result[@name='GetCustomersXml']/Customers" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
User Name: <xsl:value-of select="@Name" /> <br/>
Email Address: <xsl:value-of select="@Email" /> <br/>
</xsl:for-each>
The function itself has a number of parameters by which you can fine tune its output as you need in your markup or code.
|
•
|
Selected fields [PropertyNames] (IEnumerable<String>) |
|
•
|
Filter (Expression<Func<Customers,Boolean>>) |
|
•
|
Order by [OrderByField] (String ) |
|
•
|
OrderAscending (Boolean) |
|
•
|
Show reference data inline [ShowReferencesInline] (Boolean) |
|
•
|
IncludePagingInfo (Boolean) |
|
•
|
ElementNamespace (XNamespace) |
|
•
|
CachePriority (GetXmlCachePriority) |
Each parameter or a group of parameters serve their own purpose in retrieving or presenting data as XML. By setting these parameters, you can: