This library provides the inverse functionality of the sgml.pl parser library, writing XML, SGML and HTML documents from the parsed output. It is intended to allow rewriting in a different dialect or encoding or to perform document transformation in Prolog on the parsed representation.
The current implementation is particularly keen on getting character encoding and the use of character entities right. Some work has been done providing layout, but space handling in XML and SGML make this a very hazardous area.
The Prolog-based low-level character and escape handling is the real bottleneck in this library and will probably be moved to C in a later stage.
- xml_write(+Data, +Options) is det
- sgml_write(+Data, +Options) is det
- html_write(+Data, +Options) is det
- xml_write(+Stream, +Data, +Options) is det
- sgml_write(+Stream, +Data, +Options) is det
- html_write(+Stream, +Data, +Options) is det
- Write a term as created by the SGML/XML parser to a stream in
SGML or XML format. Options:
true(default), remove duplicate
- The DTD. This is needed for SGML documents that contain elements with content model EMPTY. Characters which may not be written directly in the Stream's encoding will be written using character data entities from the DTD if at all possible, otherwise as numeric character references. Note that the DTD will NOT be written out at all; as yet there is no way to write out an internal subset, though it would not be hard to add one.
- Document type for the SGML document type declaration.
If omitted it is taken from the root element. There is
never any point in having this be disagree with the
root element. A <!DOCTYPE> declaration will be written
if and only if at least one of
system(_)is provided in Options.
- public PubId
- The public identifier to be written in the <!DOCTYPE> line.
- The system identifier to be written in the <!DOCTYPE> line.
- If Bool is 'false', do not emit the <xml ...> header line. (xml_write/3 only)
- When emitting embedded XML, assume these namespaces are already defined from the environment. (xml_write/3 only).
- Indentation of the document (for embedding)
- Emit/do not emit layout characters to make output readable.
- Use/do not use Null End Tags.
For XML, this applies only to empty elements, so you get
<foo/> (default, net(true)) <foo></foo> (net(false))
For SGML, this applies to empty elements, so you get
<foo> (if foo is declared to be EMPTY in the DTD) <foo></foo> (default, net(false)) <foo// (net(true))
and also to elements with character content not containing /
<b>xxx</b> (default, net(false)) <b/xxx/ (net(true)).
Note that if the stream is UTF-8, the system will write special characters as UTF-8 sequences, while if it is ISO Latin-1 it will use (character) entities if there is a DTD that provides them, otherwise it will use numeric character references.
- xmlns(?NS, ?URI) is nondet[multifile]
- Hook to define human readable abbreviations for XML namespaces.
xml_write/3 tries these locations:
- This hook
- Defaults (see below)
- rdf_db:ns/2 for RDF-DB integration
Default XML namespaces are:
xsi http://www.w3.org/2001/XMLSchema-instance xs http://www.w3.org/2001/XMLSchema xhtml http://www.w3.org/1999/xhtml soap11 http://schemas.xmlsoap.org/soap/envelope/ soap12 http://www.w3.org/2003/05/soap-envelope
The following predicates are exported, but not or incorrectly documented.