⬆️ ⬇️

What is XML Sapiens

In 1995, Vignette introduced the first commercial CMS (Content Management System) class system to the market. Since then, the number of commercial CMS has been growing tirelessly and nowadays the term CMS itself has taken root in the market and, as a rule, does not require decoding. In recent years, many open standards have been approved, allowing to structure information on sites, to separate it from design, but, as before, most CMS do not follow them. For many years now, XSLT has been a standard that allows the formation of documents from separate sources: an XML file with structured document content and an XSL template describing how the document will be presented on the site.



Moreover, the very formation of the document can occur on the client side. It is enough to pass to the browser an XML data structure containing a link to the XSL template and the browser itself "draws" the page as intended by the designers. The content of each page of the site is different, but the form for submitting this content is usually limited to a small number of templates. Thus, XSLT allows us to reuse once written template for presenting data on the site. It would seem that here it is the ideal technology for CMS. However, the widespread use of this technology inhibits a number of factors. Of these, psychological inertia is not the main factor. Describing site functionality with XSLT is a very time consuming task. In addition, the XSL template is too dependent on the XML document with the data, which limits the flexibility of solutions based on this technology.



Thus, XSLT is a conceptually flawless, but in practice, time consuming solution. This circumstance encourages developers to look for new solutions that include the advantages of approved open standards and, at the same time, are relatively easy to use. One such solution is the declarative language XML Sapiens (www.xmlsapiens.org).

')

How XML Sapiens works





As with XSLT, a specific template must be associated with each site document. A template can contain any presentation code (for example, HTML) and XML Sapiens instructions. Multiple files can be included in a template. To do this, use the sapi: include instruction, which is close to the analogue in the open standard xInclude.



<sapi:include href="__" parse="template" />



Other XML Sapiens instructions allow you to deliver content and function blocks to a document.



The purpose of this decision is to separate the description of the structures of content and functionality. This allows you to once create a set of frameworks of the structures of content and functionality and then use it as a constructor when building a site.



XML Sapiens and Data





XML Sapiens includes such a concept as interface state. This allows you to define different sets of data for the same page on the site, depending on external or specified conditions. Suppose if a user is authorized on the site, the page may contain some fields of content, if others are not authorized. The states of the page content field set are defined in a separate XML document. In order to apply the set, it is enough to perform the inclusion of the set for the specified state:



<sapi:include href="___" parse="fieldset" state="a2" />



A set of fields contains data delivery instructions. These instructions associate the specified data identifier with the field type described in the external XML document.



<sapi: apply name = "qc.identifier.value" type = "type" href = "type_description_address" />



An XML document of a field type, as in the case of a set of fields, may contain type descriptions for various interface states. If the system has the “administration” and “content delivery” states, then in the first case the data can be presented in the form of a content request, in the second “as is”.



Content markup



XML Sapiens and Functionality





The page template may also contain instructions for requesting a script functionality. The algorithm for this script is described in the specified XML file.



<sapi:apply name="ddc.menu.value" href="_" />



The functional algorithm description document (DDC) contains instructions for analyzing conditions, similar to XSLT. The DDC syntax also allows you to refer to CMS applications that, according to the passed parameters, return data streams for further analysis of conditions.



<sapi version="2.0" xmlns:sapi="http://www.xmlsapiens.org/spec/sapi.dtd">

<sapi:ddc name="sample">

<sapi:choose>

<sapi:when exp="eq(this_record_id.value,0)">

<sapi:for-each select="cms_application()" name="enum">

<sapi:params>

<sapi:param name="param1">value1</sapi:param>

<sapi:param name="param2">value2</sapi:param>

</sapi:params>

<sapi:ifempty>Records not found</sapi:ifempty>

<sapi:fallback>CMS-application error</sapi:fallback>



<sapi:choose>

<sapi:when exp="gt(this.this.___.value,0)">

<sapi:code>

Sample code, &this.this.___.value;

</sapi:code>

</sapi:when>

</sapi:choose>

</sapi:when>

</sapi:choose>

</sapi:ddc>

</sapi>





When requesting a functional script, it is allowed to specify the parameters of the query, allowing the reuse of functional scripts.



<sapi:apply name="ddc.menu.value" href="http://site.com/ddc/menu.xml">

<sapi:param name="param1">value1</sapi:param>

<sapi:param name="param2">value2</sapi:param>

</sapi:apply>





Markup functionality



As you can see, XML Sapiens allows you to prepare a set of descriptions of data structures, types of content fields and functionality and further use in the design of the site. The possibility of repeated use of these components reduces the development time of web projects, avoiding system programming. Moreover, XML Sapiens is universal. It can be used in CMS, written in any software language.



The language has existed for over a year, and the second version of the language was recently published. This gives hope that the language will be further developed and used. At present, only a few CMS are functioning on the basis of this language. However, if this number increases, the exchange of functional solutions between developers using different CMS can become commonplace.

Source: https://habr.com/ru/post/6582/



All Articles