Skip to main content

Encoding and Decoding

iXML provides encode/decode operations for cryptographic hashing, phonetic encoding, compression, encryption, character escaping, transfer encoding, and structured data formats. Most encode operations have a complementary decode counterpart.

Cryptographic Hashing

encode:hash

Generates a cryptographic hash using a specified algorithm. Supports HMAC when a key is provided.

XML
<encode:hash var="signature" algorithm="sha256" key="$api_key">
$request_data
</encode:hash>
warning

Use SHA-256 or higher for security-sensitive operations. Never use plain MD5/SHA-1 for password storage.

Full reference →

encode:md5 / encode:sha1

Convenience commands for MD5 (32-char hex) and SHA-1 (40-char hex) hashing. Equivalent to encode:hash with the respective algorithm.

XML
<output><encode:md5>My name is iXML!</encode:md5></output>
<!-- 1eee4eaee83273f381b9158ac42c6ba5 -->

encode:md5 reference → | encode:sha1 reference →

encode:crc32

Generates a 32-bit cyclic redundancy checksum for error detection (not security). Returns a signed integer.

XML
<output><encode:crc32>My name is iXML!</encode:crc32></output>
<!-- 812420598 -->

Full reference →

Phonetic Encoding

encode:soundex / encode:metaphone

Generate phonetic keys for fuzzy name matching. Soundex produces a 4-character code; Metaphone uses English pronunciation rules for higher accuracy.

XML
<output><encode:soundex>Smith</encode:soundex></output>
<!-- S530 (same as "Smythe") -->

<output><encode:metaphone>Knight</encode:metaphone></output>
<!-- NXT (silent 'k') -->
note

Metaphone is more accurate than Soundex for English text. Prefer encode:metaphone for English-language applications.

encode:soundex reference → | encode:metaphone reference →

Compression

encode:deflate / decode:deflate

Compress and decompress data using the DEFLATE algorithm (RFC 1951). The level attribute (0-9) controls the compression/speed trade-off.

XML
<encode:deflate var="compressed" level="9">$large_text</encode:deflate>
<decode:deflate var="original">$compressed</decode:deflate>
note

DEFLATE produces raw compressed data without headers or checksums. Use encode:zlib for compression with error detection.

encode:deflate reference → | decode:deflate reference →

encode:zlib / decode:zlib

Compress and decompress using the ZLIB format (RFC 1950), which wraps DEFLATE with headers and an Adler-32 checksum for error detection.

XML
<encode:zlib var="compressed" level="6">$data</encode:zlib>
<decode:zlib var="original">$compressed</decode:zlib>

encode:zlib reference → | decode:zlib reference →

Encryption

encode:crypt / decode:crypt

Symmetric-key encryption and decryption. Requires a cipher (e.g. aes-256-cbc), key, and stores/consumes an initialization vector (IV).

XML
<!-- Encrypt -->
<encode:crypt var="ciphertext" var_iv="iv" cipher="aes-256-cbc" key="$encryption_key">
$plaintext
</encode:crypt>

<!-- Decrypt -->
<decode:crypt var="plaintext" cipher="aes-256-cbc" key="$encryption_key" iv="$iv">
$ciphertext
</decode:crypt>
warning

Never hardcode encryption keys in source code. Store IVs alongside ciphertext -- they are required for decryption. Use authenticated encryption modes (GCM) when possible.

encode:crypt reference → | decode:crypt reference →

Character Escaping

encode:xml / decode:xml

Encode/decode XML entities (& " < >). Always XML-encode user-supplied content before embedding in XML documents.

XML
<output><decode:xml>My name is &quot;iXML&quot; &amp; I am a XML derivative!</decode:xml></output>
<!-- My name is "iXML" & I am a XML derivative! -->

encode:xml reference → | decode:xml reference →

encode:html / decode:html

Like XML encoding but also converts newlines to <br /> and preserves spacing with &nbsp;. decode:html strips HTML tags and decodes entities.

XML
<output><encode:html>$user_comment</encode:html></output>
warning

Always HTML-encode user-supplied content to prevent XSS attacks.

encode:html reference → | decode:html reference →

encode:url / decode:url

Percent-encode/decode text for safe use in URLs (RFC 1738).

XML
<set var="url">https://example.com/search?q=<encode:url>$search_query</encode:url></set>

encode:url reference → | decode:url reference →

Transfer Encoding

encode:base64 / decode:base64

Encode/decode data using MIME Base64 (RFC 2045). Used for embedding binary data in text formats like JSON, XML, and email.

XML
<output><encode:base64>My name is iXML!</encode:base64></output>
<!-- TXkgbmFtZSBpcyBpWE1MIQ== -->

<output><decode:base64>SGVsbG8gV29ybGQ=</decode:base64></output>
<!-- Hello World -->

encode:base64 reference → | decode:base64 reference →

encode:quotedprint / decode:quotedprint

Quoted-printable encoding (RFC 2045) for mostly-ASCII text. More efficient than Base64 when data is primarily printable characters.

XML
<output><encode:quotedprint>Hello World!
My name is iXML!</encode:quotedprint></output>
<!-- Hello World!=0AMy name is iXML! -->

encode:quotedprint reference → | decode:quotedprint reference →

Structured Data Formats

encode:json / decode:json

Convert between iXML variables and JSON (RFC 4627). Associative arrays become JSON objects; numeric arrays become JSON arrays. Use pretty="true" for formatted output.

XML
<!-- Encode -->
<array var="response">
<set var="status">success</set>
<set var="message">User created</set>
</array>
<output><encode:json var="response"/></output>

<!-- Decode -->
<decode:json var="data">{"status":"success","user":{"id":123,"name":"John"}}</decode:json>
<output>$data.user.name</output>
<!-- John -->
warning

decode:json must use the var attribute. Without it, the result is an unusable internal reference.

encode:json reference → | decode:json reference →

encode:csv / decode:csv

Encode/decode comma-separated values. Input/output is a multidimensional array (rows of columns). Default delimiter is ;.

XML
<decode:csv var="data" delimiter=";">
First Name;Last Name
Bill;Gates
Steve;Jobs
</decode:csv>

<foreach var="data" var_value="row">
<output>$row.0 $row.1</output>
</foreach>

encode:csv reference → | decode:csv reference →

encode:binary / decode:binary

Pack/unpack array values into binary data using Perl/PHP-compatible format strings. Used for binary protocols and file formats.

XML
<array var="packet">
<item>0x01</item>
<item>42</item>
<item>1024</item>
</array>
<encode:binary var="packet" var_result="binary_packet" format="CCN"/>

encode:binary reference → | decode:binary reference →