DeSerialization of Smartform Contents in Ektron

Dream. Dare. Do – that is Suyati’s work principle in a nutshell.

May
08
2013
  • Author:
  • Bisileesh Bhaskaran

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:

news
Image Source: www.debbiereganlocations.com

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=”http://www.w3.org/2001/XMLSchema”>
<xs:element name=”root”>
<xs:complexType>
<xs:sequence>
<xs:element name=”News”>
<xs:complexType>
<xs:sequence>
<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:complexType>
<xs:sequence>
<xs:element name=”img” type=”imgDesignType” minOccurs=”0″ />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name=”Summary” type=”xs:string” />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:simpleType name=”dateOrBlankType”>
<xs:union memberTypes=”xs:date”>
<xs:simpleType>
<xs:restriction base=”xs:string”>
<xs:length value=”0″ />
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
<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>
<xs:attributeGroup name=”i18n”>
<xs:attribute name=”lang” type=”xs:language” />
<xs:attribute name=”dir”>
<xs:simpleType>
<xs:restriction base=”xs:token”>
<xs:enumeration value=”ltr” />
<xs:enumeration value=”rtl” />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:attributeGroup>
<xs:attributeGroup name=”attrs”>
<xs:attributeGroup ref=”coreattrs” />
<xs:attributeGroup ref=”i18n” />
</xs:attributeGroup>
<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:restriction>
</xs:simpleType>
<xs:simpleType name=”Length”>
<xs:restriction base=”xs:string”>
<xs:pattern value=”[-+]?(d+|d+(.d+)?%)” />
</xs:restriction>
</xs:simpleType>
<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” />
</xs:complexType>
</xs:schema>

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()

Image1

  •  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:

Image2

 

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:

Image3

  • 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.
CodeBehind:

Image4

 

ASPX Page:

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

Image5

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

Happy Coding!!!

Sources: 

 

Leave a Comment

Your email address will not be published. Required fields are marked *