Data Centric Functions

Getting Data as XML

When you create a data type in C1 CMS, 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 data type as an enumerable list of XML elements (XElements).

The function is placed within the namespace the data type belongs to, and its name follows this pattern:

Get<DataType>XML

where <DataType> stands for the name of the data type.

For example, if you create a data type called Demo.Customers, C1 CMS 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=""/> 

Listing 1: A data item presented as an XML element

In this element:

  • the name is that of the data type (without namespaces)
  • the attributes are the names of the fields in the data type
  • the attribute values are the values in the data type 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>

Listing 2: Iterating a data type via its data-centric function

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)
  • PageSize (Int32)
  • PageNumber (Int32)
  • Show reference data inline [ShowReferencesInline] (Boolean)
  • IncludePagingInfo (Boolean)
  • Randomized (Boolean)
  • ElementName (String)
  • 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: