package xtmpl

  1. Overview
  2. Docs

Module Xtmpl.XmlSource

Regular XML trees.

Sourcemodule SMap : Map.S with type key = string

Errors

Sourcetype Types.error +=
  1. | Parse_error of Types.loc * string
Sourceval parse_error : Types.loc -> string -> 'a

XML documents

Sourcemodule Name : Map.OrderedType with type t = string * string
Sourcemodule Name_map : Map.S with type key = Name.t
Sourceval string_of_name : Name.t -> string
Sourceval name_of_string : string -> Name.t

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

Sourcemodule P : sig ... end

XML documents with string*string as names and optionnaly located string as attribute values.

include Types.S with type name = Name.t and type attr_value = P.attr_value and type attributes = P.attr_value Name_map.t and type data = unit
Sourcetype name = Name.t
Sourcetype attr_value = P.attr_value
Sourcetype attributes = P.attr_value Name_map.t
Sourcetype data = unit
Sourcetype proc_inst = {
  1. loc : Types.loc option;
  2. app : name;
  3. args : string;
}
Sourcetype xml_decl = {
  1. loc : Types.loc option;
  2. atts : attributes;
}
Sourcetype doctype = {
  1. loc : Types.loc option;
  2. name : name;
  3. args : string;
}
Sourcetype node = {
  1. loc : Types.loc option;
  2. name : name;
  3. atts : attributes;
  4. subs : tree list;
  5. data : data;
}
Sourceand tree =
  1. | E of node
  2. | D of Types.cdata
  3. | C of Types.comment
  4. | PI of proc_inst
Sourcetype prolog_misc =
  1. | PC of Types.comment
  2. | PPI of proc_inst
Sourcetype prolog = {
  1. decl : xml_decl option;
  2. misc : prolog_misc list;
  3. doctype : doctype option;
}
Sourcetype doc = {
  1. prolog : prolog;
  2. elements : tree list;
}
Sourceval compare_doc : doc -> doc -> int
Sourceval compare_tree : tree -> tree -> int

Constructors

Sourceval node_ : ?loc:Types.loc -> name -> ?atts:attributes -> ?data:data -> tree list -> node
Sourceval node : ?loc:Types.loc -> name -> ?atts:attributes -> ?data:data -> tree list -> tree
Sourceval cdata_ : ?loc:Types.loc -> ?quoted:bool -> string -> Types.cdata
Sourceval cdata : ?loc:Types.loc -> ?quoted:bool -> string -> tree
Sourceval comment_ : ?loc:Types.loc -> string -> Types.comment
Sourceval comment : ?loc:Types.loc -> string -> tree
Sourceval prolog_comment : ?loc:Types.loc -> string -> Types.comment
Sourceval pi_ : ?loc:Types.loc -> name -> string -> proc_inst
Sourceval pi : ?loc:Types.loc -> name -> string -> tree
Sourceval prolog_pi : ?loc:Types.loc -> name -> string -> proc_inst
Sourceval xml_decl : ?loc:Types.loc -> attributes -> xml_decl
Sourceval doctype : ?loc:Types.loc -> name -> string -> doctype
Sourceval prolog : ?decl:xml_decl -> ?doctype:doctype -> prolog_misc list -> prolog
Sourceval doc : prolog -> tree list -> doc
Sourceval doc_empty : unit -> doc

Handling attributes

Sourceval get_att : attributes -> name -> attr_value option

get_att atts name returns the value associated to given attribute, if any.

Sourceval opt_att : attributes -> ?def:attr_value -> name -> attr_value

opt_att atts ?def name returns the value associated to given attribute, or the default value specified by ?def. If def is not specified, P.default_attr_value is used.

Sourceval atts_of_list : ?atts:attributes -> (name * attr_value) list -> attributes

atts_of_list list returns a attributes structure from the given list of pairs (name, value) ; (name, value) ; ....

  • parameter atts

    can be used to specify an existing attributes structure to add bindings to, instead of starting from an empty one.

Sourceval atts_one : ?atts:attributes -> name -> attr_value -> attributes

atts_one ?atts name value is like atts_of_list but for one attribute.

Sourceval atts_remove : name -> attributes -> attributes

atts_remove name attributes removes the binding to name from the attributes.

Sourceval atts_replace : name -> attr_value -> attributes -> attributes

atts_replace name value attributes adds a new bindings from name to value in attributes. If name was previously bound, the previous binding is removed.

Sourceval atts_fold : (name -> attr_value -> 'acc -> 'acc) -> attributes -> 'acc -> 'acc
Sourceval atts_empty : unit -> attributes

Printers

Sourceval pp_doc : Format.formatter -> doc -> unit
Sourceval pp : Format.formatter -> doc -> unit
Sourceval pp_attr : ?first:bool -> Format.formatter -> name -> attr_value -> unit
Sourceval pp_attributes : Format.formatter -> attributes -> unit
Sourceval pp_trees : Format.formatter -> tree list -> unit
Sourceval doc_to_string : doc -> string
Sourceval to_string : tree list -> string
Sourceval string_of_xml : tree -> string

Text extraction

Sourceval doctype_name : doc -> name option
Sourceval text_of_xmls : tree list -> string
Sourceval text_of_range : tree -> tree -> tree option -> string
Sourcemodule Name_set : Set.S with type elt = Name.t
Sourcemodule SSet : Set.S with type elt = string

Parsing

Sourcetype parse_param = {
  1. ignore_unclosed : bool;
    (*

    auto-close unclosed elements

    *)
  2. self_closing : SSet.t;
    (*

    self-closing elements

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

    entity references to unescape to utf-8 chars

    *)
}
Sourceval default_parse_param : parse_param

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

Sourceval xml_entities : Uchar.t SMap.t

mapping from XML entities to utf-8 code points

Sourceval html_entities : Uchar.t SMap.t

mapping from XML entities to utf-8 code points

mapping from HTML entities to utf-8 code points

Sourceval 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.

Sourceval from_string : ?param:parse_param -> ?pos_start:Types.pos -> string -> tree list
Sourceval from_channel : ?param:parse_param -> ?pos_start:Types.pos -> in_channel -> tree list
Sourceval from_file : ?param:parse_param -> string -> tree list
Sourceval doc_from_string : ?param:parse_param -> ?pos_start:Types.pos -> string -> doc
Sourceval doc_from_channel : ?param:parse_param -> ?pos_start:Types.pos -> in_channel -> doc
Sourceval doc_from_file : ?param:parse_param -> string -> doc