Go to the first, previous, next, last section, table of contents.

HTML/XML/CGI programming

Author(s): Daniel Cabeza, Manuel Hermenegildo, Sacha Varma.

Version: 1.7#40 (2001/1/5, 19:7:40 CET)

Version of last change: 1.5#114 (2000/4/11, 20:23:43 CEST)

This module implements the predicates of the PiLLoW package related to HTML/ XML generation and parsing, CGI and form handlers programming, and in general all the predicates which do not imply the use of the HTTP protocol.

Usage and interface (html)

Documentation on exports (html)

PREDICATE: output_html/1:


Outputs HTMLTerm, interpreted as an html_term/1, to current output stream.


PREDICATE: html2terms/2:


String is a character list containing HTML code and Terms is its prolog structured representation.

Usage 1:

Usage 2:

PREDICATE: xml2terms/2:


String is a character list containing XML code and Terms is its prolog structured representation.

Usage 1:

Usage 2:

PREDICATE: html_template/3:


Interprets Chars as an HTML template returning in Terms the corresponding structured HTML-term, which includes variables, and unifying Dict with a dictionary of those variables (an incomplete list of name=Var pairs). An HTML template is standard HTML code, but in which "slots" can be defined and given an identifier. These slots represent parts of the HTML code in which other HTML code can be inserted, and are represented in the HTML-term as free variables. There are two kinds of variables in templates:

As an example, suposse the following HTML template:

<body bgcolor=_bgcolor>

The following query in the Ciao toplevel shows how the template is parsed, and the dictionary returned:

?- file_to_string('template.html',_S), html_template(_S,Terms,Dict). 

Dict = [bgcolor=_A,content=_B|_],
Terms = [env(html,[],["
"] ? 


If a dictionary with values is supplied at call time, then variables are unified accordingly inside the template:

?- file_to_string('template.html',_S),
   html_template(_S,Terms,[content=b("hello world!"),bgcolor="white"]). 

Terms = [env(html,[],["
",b("hello world!"),"
"] ? 



PREDICATE: html_report_error/1:

Usage: html_report_error(Error)

PREDICATE: get_form_input/1:


Translates input from the form (with either the POST or GET methods, and even with CONTENT_TYPE multipart/form-data) to a dictionary Dict of attribute=value pairs. It translates empty values (which indicate only the presence of an attribute) to the atom '$empty', values with more than one line (from text areas or files) to a list of lines as strings, the rest to atoms or numbers (using name/2).


PREDICATE: get_form_value/3:


Unifies Val with the value for attribute Var in dictionary Dict. Does not fail: value is " if not found (this simplifies the programming of form handlers when they can be accessed directly).


PREDICATE: form_empty_value/1:

Usage: form_empty_value(Term)

PREDICATE: form_default/3:

Usage: form_default(Val,Default,NewVal)

PREDICATE: set_cookie/2:


Sets a cookie of name Name and value Value. Must be invoked before outputting any data, including the cgi_reply html-term.


PREDICATE: get_cookies/1:


Unifies Cookies with a dictionary of attribute=value pairs of the active cookies for this URL.


PREDICATE: url_query/2:


Translates a dictionary Dict of parameter values into a string URLArgs for appending to a URL pointing to a form handler.


PREDICATE: my_url/1:


Unifies URL with the Uniform Resource Locator (WWW address) of this cgi executable.


PREDICATE: url_info/2:


Translates a URL URL to a Prolog structure URLTerm which details its various components, and vice-versa. For now non-HTTP URLs make the predicate fail.

Usage 1:

Usage 2:

Usage 3:

PREDICATE: url_info_relative/3:


Translates a relative URL URL which appears in the HTML page refered to by BaseURLTerm into URLTerm, a Prolog structure containing its absolute parameters. Absolute URLs are translated as with url_info/2. E.g.

                  http('www.foo.com',80,"/bar/scoob.html"), Info)

gives Info = http('www.foo.com',80,"/bar/dadu.html").

Usage 1:

Usage 2:

PREDICATE: form_request_method/1:

Usage: form_request_method(Method)

PREDICATE: icon_address/2:


The PiLLoW image Img has URL IAddress.


PREDICATE: html_protect/1:


Calls Goal. If an error occurs during its execution, or it fails, an HTML page is output informing about the incident. Normaly the whole execution of a CGI is protected thus.

Meta-predicate with arguments: html_protect(goal).


PREDICATE: http_lines/3:

Usage: http_lines(Lines,String,Tail)

Documentation on multifiles (html)

PREDICATE: html_expansion/2:

The predicate is multifile.

Usage: html_expansion(Term,Expansion)

Other information (html)

The code uses input from from L. Naish's forms and F. Bueno's previous Chat interface. Other people who have contributed is (please inform us if we leave out anybody): Markus Fromherz, Samir Genaim.

Go to the first, previous, next, last section, table of contents.