package xtmpl

  1. Overview
  2. Docs

Regular XML trees.

module SMap : Map.S with type key = string

Errors

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

XML documents

module Name : Map.OrderedType with type t = string * string
module Name_map : Map.S with type key = Name.t
val string_of_name : Name.t -> string
val 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).

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

Constructors

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

Handling attributes

val get_att : attributes -> name -> attr_value option

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

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

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

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

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

val atts_remove : name -> attributes -> attributes

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

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

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

Printers

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

Text extraction

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

Parsing

type 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

    *)
}
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 from_string : ?param:parse_param -> ?pos_start:Types.pos -> string -> tree list
val from_channel : ?param:parse_param -> ?pos_start:Types.pos -> in_channel -> tree list
val from_file : ?param:parse_param -> string -> tree list
val doc_from_string : ?param:parse_param -> ?pos_start:Types.pos -> string -> doc
val doc_from_channel : ?param:parse_param -> ?pos_start:Types.pos -> in_channel -> doc
val doc_from_file : ?param:parse_param -> string -> doc
OCaml

Innovation. Community. Security.