Encoding and the Render Engine

Release 1.0 - ...

Since the iXperion render engine is an XML compliant processor, XML encoding and decoding are an important part of iXperion. The SXML input needs to be well-formed XML and like all XML readers, the iXperion render engine by default decodes all output that is sent to the client.

If this is the SXML input:

HTML CopyCode image Copy Code
<html>
<body>
  &lt;p&gt;Hi this is a test for you &amp;amp; me.&lt;/p&gt;
</body>
</html>
the following is sent to the output:
HTML CopyCode image Copy Code
<html>
<body>
  <p>Hi this is a test for you &amp; me.</p>
</body>
</html>
The output is decoded once. This output decoding behavior can be altered by using the response.setoutputdecoding viper. The default output decoding includes the following XmlCodingOptions: Xml and SkipCDATA

Double ampersand encoding

The fact that the render engine output is XML decoded before being sent to the client causes some unexpected results when using encoding vipers. Any xml encode operation on the server will be nullified by the default output xml decoding performed by the render engine. In order to avoid this behavior all standard encoding vipers perform a double ampersand encode where a single & character is encoded as &amp;amp;.

SXML input Output (server) Output (client)
{string.xmlencode("&lt;")} &amp;amp;lt; &amp;lt;

Without the double ampersand encode, the client output would be the same as the input string as is demonstrated below:

SXML input Output (server) Output (client)
{string.xmlencode("&lt;")} &amp;lt; &lt;

The client output is the same as the original SXML input string when double ampersand encoding is not used. This behavior is not what a site builder expects and this has been the sole reason to introduce the double ampersand encoding. Double ampersand encoding is applied to all the XML related encoding and decoding vipers, except for string.encodeampersand and string.decodeampersand.

Custom Xml Encoding with XmlCodingOptions

The string.xmldecode and string.xmlencode vipers both have overloads with an XmlCodingOptions parameter. The XmlCodingOptions allows for fine-grained control over the characters that should be encoded or decoded. You can supply multiple values at once by specifying a comma seperated string. For example; string.xmlencode(s, 'ampersand, lessthan') encodes both & and < characters.    

Option Description
none No characters are encoded or decoded.
lessthan Includes the < character (encoded: &lt;)
greaterthan Includes the > character (encoded: &gt;)
ampersand Includes the & character (encoded: &amp;)
apostrophe Includes the ' character (encoded: &apos;)
quotationmark Includes the " character (encoded: &quot;)
viperdirective Includes the { character (encoded: &#123;)
numericentities Includes numeric entities decoding. This option is only useful when decoding XML
characterentities Includes character entities decoding. This option is only useful when decoding XML and when a character reference dictionary is provided.
skipcdata Indicates that contents of CDATA blocks (<![CDATA[ ]]> should be ignored.
skipcomments Indicates that contents of comments blocks (<!-- -->) should be ignored.
doubleampersand Ampersands are encoded/decoded twice
xml The combination of lessthan, greaterthan, ampersand, apostrophe, quotationmark and numericentities
sxml The combination of xml and viperdirective
html The combination of xml and characterentities