DeSerialization of Smartform Contents in Ektron

Smartforms are one of the important Content Types in Ektron. They are basically meant to structure or model the content, which allows the content authors to create structured contents. Thus they will separate the content from presentation.

Let us look into content modelling using Smart from with the following example,

Suppose you have an online Entertainment news website, the news contents that appears in this website should have the following attributes:

• News Title
• News Author Name
• News Content
• News Image
• News Summary
• News Date.etc

A typical Entertainment News content:

Image Source:

In the above example certain attributes are mandatory. For example News Content, Author Name, Date,.etc.And the rest of them are optional.
The content authors may miss some of the required attributes while creating the content, or may not provide the needed styling for the content. Thus a non-structured content will become a headache for the whole system.

Smart forms will rectify all these issues by providing a model to the content. It forces the content to be of a certain format.

Now let us create a New Smartform definition in the workarea with the above fields.

View SF config

Now we will create a “News Content” with this Smart form,

SF Content

Now the question is how to retrieve the Smartform content data? Mostly Ektron developer seems to be comfortable with the following three approaches.

  • Approach -1:

Generate Class for SmartForm

This approach refers to creating a class from the XML Defnition Schema of the Smart form configuration,which can be obtained from the smartorm designer in the workarea.

Generate class from the xsd by using

• Xsd.exe or
• Xsd2Code .net class generator from XSD schema

The xsd schema for our sample Smart Form looks like the following:

<xs:schema elementFormDefault=”qualified” attributeFormDefault=”unqualified” xmlns:xs=””>
<xs:element name=”root”>
<xs:element name=”News”>
<xs:element name=”Title” type=”xs:string” />
<xs:element name=”Author” type=”xs:string” />
<xs:element name=”Content” type=”xs:string” />
<xs:element name=”Date” type=”dateOrBlankType” />
<xs:element name=”Image”>
<xs:element name=”img” type=”imgDesignType” minOccurs=”0″ />
<xs:element name=”Summary” type=”xs:string” />
<xs:simpleType name=”dateOrBlankType”>
<xs:union memberTypes=”xs:date”>
<xs:restriction base=”xs:string”>
<xs:length value=”0″ />
<xs:attributeGroup name=”coreattrs”>
<xs:attribute name=”id” type=”xs:ID” />
<xs:attribute name=”class” type=”xs:NMTOKENS” />
<xs:attribute name=”style” type=”xs:string” />
<xs:attribute name=”title” type=”xs:string” />
<xs:attributeGroup name=”i18n”>
<xs:attribute name=”lang” type=”xs:language” />
<xs:attribute name=”dir”>
<xs:restriction base=”xs:token”>
<xs:enumeration value=”ltr” />
<xs:enumeration value=”rtl” />
<xs:attributeGroup name=”attrs”>
<xs:attributeGroup ref=”coreattrs” />
<xs:attributeGroup ref=”i18n” />
<xs:simpleType name=”ImgAlign”>
<xs:restriction base=”xs:token”>
<xs:enumeration value=”top” />
<xs:enumeration value=”middle” />
<xs:enumeration value=”bottom” />
<xs:enumeration value=”left” />
<xs:enumeration value=”right” />
<xs:simpleType name=”Length”>
<xs:restriction base=”xs:string”>
<xs:pattern value=”[-+]?(d+|d+(.d+)?%)” />
<xs:complexType name=”imgDesignType”>
<xs:attributeGroup ref=”attrs” />
<xs:attribute name=”src” use=”required” type=”xs:anyURI” />
<xs:attribute name=”alt” type=”xs:string” />
<xs:attribute name=”height” type=”Length” />
<xs:attribute name=”width” type=”Length” />
<xs:attribute name=”align” type=”ImgAlign” />
<xs:attribute name=”border” type=”Length” />
<xs:attribute name=”hspace” type=”xs:nonNegativeInteger” />
<xs:attribute name=”vspace” type=”xs:nonNegativeInteger” />

Once the corresponding class is created with the XSD, it is possible to De-serialize the smartform content to corresponding class.

And from the De-serialized entity, the data can be accessed as corresponding class members.
For example,

public void ClassHandling()


  •  Approach-2:

XML Parsing: 
Another approach is parsing the XML data of the smartform content,as the smartform contents are enforced to have XML data,this can be pulled programmatically and can be parsed to obtain the required data.
The XML of the Sample Smartform content looks like this:



The XML data of the corresponding Smartform content can be accessed from the ContentData class from the ContentManager framework class.

The XML parsing can be done in different ways as there are number of classes in the .NET framework to work with XML.
According to the Best practice strategy, it is better to make use of the XPathNavigator class as is much efficient in performance perspective, as it doesn’t provide any editing capabilities.

Sample code looks like the following:


  • Approach-3:

By using JSON

This is another alternate approach to De-serialize the smartform content data.This approach refers to transforming the XML data of the smartform content into JSON format.The primary advantage of this approach is client side data binding by leveraging the parsing capabilities of JSON.



ASPX Page:

<form id=”form1″ runat=”server”>


Thus by using this approach the smartform content data binding can be done from client side.

Happy Coding!!!



Author : Bisileesh Bhaskaran Date : 08 May 2013