Encoding and the Render Engine
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 | Copy Code |
---|---|
<html> <body> <p>Hi this is a test for you &amp; me.</p> </body> </html> |
HTML | Copy Code |
---|---|
<html> <body> <p>Hi this is a test for you & me.</p> </body> </html> |
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;.
SXML input | Output (server) | Output (client) |
---|---|---|
{string.xmlencode("<")} | &amp;lt; | &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; | < |
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: <) |
greaterthan | Includes the > character (encoded: >) |
ampersand | Includes the & character (encoded: &) |
apostrophe | Includes the ' character (encoded: ') |
quotationmark | Includes the " character (encoded: ") |
viperdirective | Includes the { character (encoded: {) |
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 |