xtmpl

Xml templating library
Library xtmpl
Module Xtmpl . Xml
module SMap : Map.S with type key = string

Locations

type pos = {
line : int;
bol : int;
char : int;
file : string option;
}

A position in a source (file, string, ...).

val pos : ?file:string -> line:int -> bol:int -> char:int -> unit -> pos
type loc = {
loc_start : pos;
loc_stop : pos;
}

A location is a range defined by two positions.

val string_of_loc : loc -> string
val loc_sprintf : loc option -> ( 'a, unit, string ) format -> 'a
type 'a with_loc = 'a * loc option
val loc : pos -> pos -> loc

loc loc_start loc_stop creates a loc structure with the given positions.

Errors

type error = loc * string
exception Error of error
val error : loc -> string -> 'a
val string_of_error : (loc * string) -> string

Names

type name = string * string
val string_of_name : (string * string) -> string
val name_of_string : string -> string * string

name_of_string str cuts a name according to first ':' character. If no such character is found, return ("",str).

module Name_ord : Map.OrderedType with type t = name
module Name_map : Map.S with type key = name
module Name_set : Set.S with type elt = name
module SSet : Set.S with type elt = string

XML trees

type cdata = {
loc : loc option;
text : string;
quoted : bool;
}
type comment = {
loc : loc option;
comment : string;
}
type proc_inst = {
loc : loc option;
app : name;
args : string;
}
type 'a attributes = 'a Name_map.t
type str_attributes = string with_loc attributes
type xml_decl = {
loc : loc option;
atts : str_attributes;
}
type doctype = {
loc : loc option;
name : name;
args : string;
}
type node = {
loc : loc option;
name : name;
atts : str_attributes;
subs : tree list;
}
and tree =
| E of node
| D of cdata
| C of comment
| PI of proc_inst
type prolog_misc =
| PC of comment
| PPI of proc_inst
type prolog = {
decl : xml_decl option;
misc : prolog_misc list;
doctype : doctype option;
}
type 'a doc = {
prolog : prolog;
elements : 'a list;
}

Constructors

val node : ?loc:loc -> name -> ?atts:str_attributes -> tree list -> tree
val cdata : ?loc:loc -> ?quoted:bool -> string -> tree
val comment : ?loc:loc -> string -> tree
val prolog_comment : ?loc:loc -> string -> prolog_misc
val pi : ?loc:loc -> name -> string -> tree
val prolog_pi : ?loc:loc -> name -> string -> prolog_misc
val xml_decl : ?loc:loc -> str_attributes -> xml_decl
val doctype : ?loc:loc -> name -> string -> doctype
val prolog : ?decl:xml_decl -> ?doctype:doctype -> prolog_misc list -> prolog
val doc : prolog -> tree list -> tree doc
val merge_cdata : cdata -> cdata -> cdata
val doctype_name : 'a doc -> name option

Input/output

type parse_param = {
ignore_unclosed : bool;(*

auto-close unclosed elements

*)
self_closing : SSet.t;(*

self-closing elements

*)
entities : Uchar.t SMap.t;(*

entity references to unescape to utf-8 chars

*)
}
val default_parse_param : parse_param

Default: no self-closing tags, unescape XML entities (amp, apos,quot, lt, gt). ignore_unclosed: false.

val xml_entities : Uchar.t SMap.t

mapping from XML entities to utf-8 code points

val html_entities : Uchar.t SMap.t

mapping from XML entities to utf-8 code points

mapping from HTML entities to utf-8 code points

val unescape : parse_param -> ?entities:bool -> string -> string

Unescape character references and entity references from parse_param.entities.

  • parameter entities

    can be set to false not to unescape entity references.

val escape : ?quotes:bool -> string -> string

Replace the following characters: < by &lt;, > by &gt;, & by &amp;. Also replace simple and double quotes by &apos; and &quot; if quotes = true (which is false by default).

val from_string : ?param:parse_param -> ?pos_start:pos -> string -> tree list
val from_channel : ?param:parse_param -> ?pos_start:pos -> in_channel -> tree list
val from_file : ?param:parse_param -> string -> tree list
val doc_from_string : ?param:parse_param -> ?pos_start:pos -> string -> tree doc
val doc_from_channel : ?param:parse_param -> ?pos_start:pos -> in_channel -> tree doc
val doc_from_file : ?param:parse_param -> string -> tree doc
val to_string : tree list -> string
val doc_to_string : tree doc -> string

Attributes

val atts_empty : 'a attributes
val atts_of_list : ?atts:'a attributes -> (name * 'a) list -> 'a attributes

Same as Rewrite.atts_of_list but for generic attributes.

val atts_one : ?atts:'a attributes -> name -> 'a -> 'a attributes

Same as Rewrite.atts_one but for generic attributes.

val atts_remove : name -> 'a attributes -> 'a attributes

Same as Rewrite.atts_remove but for generic attributes.

val atts_replace : name -> 'a -> 'a attributes -> 'a attributes

Same as Rewrite.atts_replace but for generic attributes.

val get_att : 'a attributes -> name -> 'a option

Same as Rewrite.get_att but for generic attributes.

val opt_att : str_attributes -> ?def:string -> name -> string * loc option
val string_of_atts : str_attributes -> string

Return a string representation of the given str_attributes.