package stk_xml

  1. Overview
  2. Docs

Module Stk_xml.DocSource

XML View documents

When a XML document is displayed in a View.xmlview, a XML view document is created, which contains trees of nodes. Each of these nodes can point to a node in the original XML document and have an associated widget.

This view document can be used to look up for information and the associated widgets, or look up for the original XML from a widget.

Sourcemodule WMap = Stk.Widget.Map
Sourcetype node = {
  1. xml : Xml.tree option;
  2. widget : Stk.Widget.widget option;
  3. subs : node list;
  4. id : string option;
  5. container : Stk.Widget.widget;
  6. props : Css.C.t;
  7. mutable display : bool;
  8. mutable parent : node option;
}

A XML view document node.

Convenient functions on nodes

Sourceval node_widget : node -> Stk.Widget.widget option

node_widget node returns the optional widget associated to node.

Sourceval node_widget_type : node -> Stk.Widget.widget_type option

node_widget_type returns the type (method Stk.Widget.widget.typ) of the widget associated to node, if any. The function returns None if no widget is associated or if the associatd widget has no type.

Sourceval node_size : node -> (int * int) option

node_size node returns the pair (width, height) of the node widget, if any.

Sourceval node_geometry : node -> Stk.G.t option

node_geometry node returns the geometry (Stk.G.t) of the node widget, if any.

Sourceval string_of_node : node -> string

string_of_node node returns a string represention of node, only for de debugging purpose.

Sourceval get_content_text : node -> string

get_content_text node returns the content of cdata XML nodes from the XML node corresponding to node, if any (else return "").

Sourceval node_parent : ?until:(node -> bool) -> ?itself:bool -> node -> node option

node_parent node returns the parent node of node, if any. Optional parameter until can be used to specify a predicate on a node. In this case, the function recursively goes up the parent nodes until the predicate evaluates to true on a node, and this node is returned. Optional parameter itself (default is false) indicates if the node itself can be returned if it satisfies the predicate until.

Text index

Sourcemodule TI : sig ... end

Module to build a text index, allowing text-based search in a XML view document.

XML view document

Sourcetype doc = {
  1. doc_nodes : node list;
    (*

    Root nodes

    *)
  2. doc_item_map : node WMap.t;
    (*

    Mapping from widget to node

    *)
  3. doc_id_map : node Stk.Smap.t;
    (*

    Mapping from id to node

    *)
  4. mutable doc_filter : string option;
  5. mutable doc_text_index : TI.t option;
}
Sourceval doc_empty : doc

Empty document.

Sourceval find_node : doc -> (node -> bool) -> node option

find_node doc pred returns the first node satisfying predicate pred, if any.

Sourceval find_node_by_id : doc -> string -> node option

find_node_by_id doc id returns the node associated to id, if any.

Sourceval find_first_node_by_tag : doc -> string -> node option

find_first_node_by_tag doc name returns first node associated to an XML element with name name (whatever being its namespace), if any.

Sourceval build_doc_text_index : ?rebuild:bool -> ?ct:Ldp.Ct.t -> doc -> unit

build_doc_text_index doc builds the text index of doc and stores it in the document. If the text index is already present and the optional parameter rebuild is false (which is the default), then nothing is done. If optional parameter ct is provided and it belongs to Xml.html_mime_types, then the text index starts from the <body> element of the XML document (if no node correponding to a <body> element is found, the text index covers all the document nodes).