Merge branch 'lucca-tests-bench' into lucca-extentions
[tatoo.git] / src / tree.mli
1 (***********************************************************************)
2 (*                                                                     *)
3 (*                               TAToo                                 *)
4 (*                                                                     *)
5 (*                     Kim Nguyen, LRI UMR8623                         *)
6 (*                   Université Paris-Sud & CNRS                       *)
7 (*                                                                     *)
8 (*  Copyright 2010-2012 Université Paris-Sud and Centre National de la *)
9 (*  Recherche Scientifique. All rights reserved.  This file is         *)
10 (*  distributed under the terms of the GNU Lesser General Public       *)
11 (*  License, with the special exception on linking described in file   *)
12 (*  ../LICENSE.                                                        *)
13 (*                                                                     *)
14 (***********************************************************************)
15
16 (** Implementation of documents as binary trees *)
17
18 type node
19 (** The type of a tree node *)
20
21 type t
22 (** The type of trees *)
23
24 val nil : node
25 (** Nil node, denoting the first/second child of a leaf or the parent of
26     the root *)
27
28 val dummy : node
29 (** Dummy node that is guaranteed to never occur in any tree *)
30
31 val load_xml_file : in_channel -> t
32 (** Takes a file descriptor and returns the XML data stored in the
33     corresponding file. Start at the current position in the file
34     descriptor (which is not necessarily the begining of file)
35 *)
36
37 val load_xml_string : string -> t
38 (** Loads XML data stored in a string *)
39
40 val print_xml : out_channel -> t -> node -> unit
41 (** Outputs the tree as an XML document on the given output_channel *)
42
43
44 val root : t -> node
45 (** Returns the root of the tree *)
46
47 val first_child : t -> node -> node
48 (** [first_child t n] returns the first child of node [n] in tree [t].
49     Returns [nil] if [n] is a leaf. Returns [nil] if [n == nil].
50 *)
51
52 val first_child_x : t -> node -> node
53 (** [first_child t n] returns the first child which is not an attribute
54     of node [n] in tree [t].
55     Returns [nil] if [n] is a leaf. Returns [nil] if [n == nil].
56 *)
57
58 val next_sibling : t -> node -> node
59 (** [next_sibling t n] returns the next_sibling of node [n] in tree [t].
60     Returns [nil] if [n] is the last child of a node.
61     Returns [nil] if [n == nil].
62 *)
63
64 val parent : t -> node -> node
65 (** [next_sibling t n] returns the parent of node [n] in tree [t].
66     Returns [nil] if [n] is the root of the tree.
67     Returns [nil] if [n == nil].
68 *)
69
70 val is_leaf : t -> node -> bool
71 (** Return true if the node is a leaf or an attribute *)
72
73 val is_attribute : t -> node -> bool
74 (** Return true if the node is an attribute *)
75
76 val tag : t -> node -> QName.t
77 (** Returns the label of a given node *)
78
79 val data : t -> node -> string
80 (** Returns the character data associated with a node.
81     The only node having character data are those whose label is
82     QName.text, QName.cdata_section or QName.comment
83  *)
84
85 val preorder : t -> node -> int
86 (** Returns the position of a node in pre-order in the tree. The
87     root has preorder 0. [nil] has pre-order [-1].
88 *)
89
90 val print_xml_preorder : out_channel -> t -> node -> unit
91 (** Outputs the tree with IDs for nodes as an XML document on the
92     given output_channel *)
93
94 val debug_node : Format.formatter -> t -> node -> unit
95 (** DEBUG *)