Module xml

This module provides a couple of simple utilities to deal with the generation and parsing of XML and JSON texts. The predicate text_escape/2 can be used to escape and un-escape texts.  The predicate text_escape/2 will escape the characters '"<>&' and the character 0xA0. It is suitable for attribute values in double quotes and for texts.

Examples:
?- text_escape('<abc>', X).
X = '&lt;abc&gt;'
?- text_escape(X, '&lt;abc&gt;').
X = '<abc>'

The predicate base64_block/2 can be used to base64 encode and decode a byte block. This code allows representing 8-bit bytes as ASCII characters. When generating base64 code the predicate will produce 10 blocks of 4 characters effectively encoding 30 bytes. While decoding the terminating characters = indicate the number of fill bytes.

The following xml predicates are provided:
text_escape(T, E):
If T is a variable then the predicate succeeds when T unifies with the text un-escape of E. Otherwise the predicate succeeds when E unifies with the text escape of T.
html_escape(T):
html_escape(O, T):
The predicate sends the text T escaped to the current output. The binary predicate allows specifying an output stream O.
hex_block(T, E):
If T is a variable then the predicate succeeds when T unifies with the hex encode of E. Otherwise the predicate succeeds when E unifies with the hex decode of T.
base64_block(T, E):
If T is a variable then the predicate succeeds when T unifies with the based64 encode of E. Otherwise the predicate succeeds when E unifies with the base64 decode of T.

Kommentare