package stk_xml

  1. Overview
  2. Docs

Module Stk_xml.XmlSource

Xml documents and convenient functions and values.

Sourceval empty_iri : Iri.t

The empty IRI "".

XML documents

Sourcemodule QName : sig ... end

Qualified names are composed of a namespace (an IRI) and a name (string).

Sourceval qname_equal : ?no_ns:bool -> QName.t -> QName.t -> bool

qname_equal n1 n2 returns whether both qualified names are equal. Optional argument no_ns (default is false) indicates whether to compare only names and not namespaces.

Sourcemodule Attributes : Map.S with type key = QName.t

Attributes are maps with qualified names as keys.

Sourcemodule P : Xtmpl.Types.P with module Attributes = Attributes and type attr_value = string Types.with_loc_option and type data = unit
include Xtmpl.Types.S with type name = P.Attributes.key and type attr_value = P.attr_value and type attributes = P.attr_value P.Attributes.t and type data = P.data
Sourcetype attr_value = P.attr_value
Sourcetype data = P.data
Sourcetype proc_inst = {
  1. loc : Xtmpl.Types.loc option;
  2. app : name;
  3. args : string;
}
Sourcetype xml_decl = {
  1. loc : Xtmpl.Types.loc option;
  2. atts : attributes;
}
Sourcetype doctype = {
  1. loc : Xtmpl.Types.loc option;
  2. name : name;
  3. args : string;
}
Sourcetype node = {
  1. loc : Xtmpl.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 Xtmpl.Types.cdata
  3. | C of Xtmpl.Types.comment
  4. | PI of proc_inst
Sourcetype prolog_misc =
  1. | PC of Xtmpl.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:Xtmpl.Types.loc -> name -> ?atts:attributes -> ?data:data -> tree list -> node
Sourceval node : ?loc:Xtmpl.Types.loc -> name -> ?atts:attributes -> ?data:data -> tree list -> tree
Sourceval cdata_ : ?loc:Xtmpl.Types.loc -> ?quoted:bool -> string -> Xtmpl.Types.cdata
Sourceval cdata : ?loc:Xtmpl.Types.loc -> ?quoted:bool -> string -> tree
Sourceval comment_ : ?loc:Xtmpl.Types.loc -> string -> Xtmpl.Types.comment
Sourceval comment : ?loc:Xtmpl.Types.loc -> string -> tree
Sourceval prolog_comment : ?loc:Xtmpl.Types.loc -> string -> Xtmpl.Types.comment
Sourceval pi_ : ?loc:Xtmpl.Types.loc -> name -> string -> proc_inst
Sourceval pi : ?loc:Xtmpl.Types.loc -> name -> string -> tree
Sourceval prolog_pi : ?loc:Xtmpl.Types.loc -> name -> string -> proc_inst
Sourceval xml_decl : ?loc:Xtmpl.Types.loc -> attributes -> xml_decl
Sourceval doctype : ?loc:Xtmpl.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 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 TXml : sig ... end
Sourcemodule PXml : Stk.Props.Prop_type with type t = doc
Sourceval mk_prop_xml : ?after:doc Stk.Props.post_action list -> ?inherited:bool -> ?transition:doc Stk.Props.transition -> string -> doc Stk.Props.prop

Creating a Stk property with XML document as value.

Convenient functions for attributes

The try_no_ns optional parameter (which defaults to true) indicates whether if we must look for (iri_empty, name) if looking for (iri, name) fails.

Sourceval opt_att : node -> ?try_no_ns:bool -> QName.t -> P.attr_value option

opt_att node attr returns the value associated to attribute attr in node, if any.

Sourceval get_att : node -> ?try_no_ns:bool -> QName.t -> P.attr_value -> P.attr_value

get_att node attr default is the same as opt_att but returns default if no value is associatd to attr.

Sourceval map_att : node -> ?try_no_ns:bool -> QName.t -> (string -> 'a) -> 'a -> 'a

map_att node attr f default applies f on the value of attribut attr in node and returns the result. If node has no value for attr, it returns the default value.

Sourceval map_opt_att : node -> ?try_no_ns:bool -> QName.t -> (string -> 'a) -> 'a option

Same as map_att but returns None instead of a default value, or Some v with v being the result of applying f to the attribute value.

Sourceval int_att : node -> ?try_no_ns:bool -> QName.t -> int -> int

int_att node attr default is the same as map_att node attr int_of_string default.

Sourceval opt_int_att : node -> ?try_no_ns:bool -> QName.t -> int option

opt_int_att node attr is the same as map_opt_att node attr int_of_string.

Xhtml namespace

Sourceval xhtml_ns_str : string

XHTML namespace as string.

Sourceval xhtml_ns : Iri.t

XHTML namespace as IRI.

Sourceval xhtml_ : 'a -> Iri.t * 'a

xhtml_ name returns xhtml_ns, name.

Sourceval xhtml_id : QName.t

XHTML "id" qualified name.

Sourceval xhtml_name : QName.t

XHTML "name" qualified name.

Sourceval xhtml_href : QName.t

XHTML "href" qualified name.

Sourceval xhtml_class : QName.t

XHTML "class" qualified name.

Sourceval xhtml_a : QName.t

XHTML "a" qualified name.

Sourceval node_id : node -> string option

node_id node returns the content of id or else name attribute of node, if any.

Sourceval xhtml_base : tree list -> Iri.t -> Iri.t

xhtml_base trees base looks up for the <base> element in the <head> element of the <html> element and return the IRI in the href attribute. If an element is not found or the <base> element has no href or it contains an invalid IRI, then base argument is returned; else the href attribute of the <base> element is returned.

Sourceval html_self_closing_elements : Xtmpl.Xml.SSet.t

The set of element which may self-close in a XHTML document. This can be used in the param argument of doc_from_string.

Mime-types

Sourceval mime_html : Ldp.Ct.mime

HTML mime-type "text/html".

Sourceval html_mime_types : Ldp.Ct.mime list
Sourceval mime_is_xml : Ldp.Ct.mime -> bool

mime_is_xml mime returns whether mime corresponds to a an XML mime-type, i.e. it's HTML, XML or any mime-type ending with "+xml".

Input

Sourcemodule Of_xtmpl : sig ... end

Mapping from Xtmpl.Xml documents. The mapping applies namespaces to create fully qualified names.

Sourceval doc_from_string : ?base:Iri.t -> ?param:Xtmpl.Xml.parse_param -> string -> doc

doc_from_string str parses str as an Xtmpl.Xml document and map it to a doc (to have fully qualified names). Optional argument base is used to resolve IRIs. Default is the empty IRI. See Xtmpl.Xml.parse_param for optional argument param.

Sourceval from_string : ?base:Iri.t -> ?param:Xtmpl.Xml.parse_param -> ?ns:Iri.t Stk.Smap.t -> string -> tree list

Same as doc_from_string but parses XML trees, not a whole XML document. Optional argument ns can be used to define namespaces, which may be required to expand names and get qualified names.

Sourceval normalize_xmls : tree list -> tree list

normalize_xmls trees applies Stk.Utf8.normalize on all cdata elements, (and updates locations).