72cd0772dbee7609c008f919a03dbf1e2c12a8bb
[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 (*
17   Time-stamp: <Last modified on 2013-01-30 19:06:46 CET by Kim Nguyen>
18 *)
19
20 (** Implementation of documents as binary trees *)
21
22 type node
23 (** The type of a tree node *)
24
25 type t
26 (** The type of trees *)
27
28 val nil : node
29 (** Nil node, denoting the first/second child of a leaf or the parent of
30     the root *)
31
32 val dummy : node
33 (** Dummy node that is guaranteed to never occur in any tree *)
34
35 val load_xml_file : in_channel -> t
36 (** Takes a file descriptor and returns the XML data stored in the
37     corresponding file. Start at the current position in the file
38     descriptor (which is not necessarily the begining of file)
39 *)
40
41 val load_xml_string : string -> t
42 (** Loads XML data stored in a string *)
43
44 val print_xml : out_channel -> t -> node -> unit
45 (** Outputs the tree as an XML document on the given output_channel *)
46
47
48 val root : t -> node
49 (** Returns the root of the tree *)
50
51 val first_child : t -> node -> node
52 (** [first_child t n] returns the first child of node [n] in tree [t].
53     Returns [nil] if [n] is a leaf. Returns [nil] if [n == nil].
54 *)
55
56 val next_sibling : t -> node -> node
57 (** [next_sibling t n] returns the next_sibling of node [n] in tree [t].
58     Returns [nil] if [n] is the last child of a node.
59     Returns [nil] if [n == nil].
60 *)
61
62 val parent : t -> node -> node
63 (** [next_sibling t n] returns the parent of node [n] in tree [t].
64     Returns [nil] if [n] is the root of the tree.
65     Returns [nil] if [n == nil].
66 *)
67
68 val tag : t -> node -> QName.t
69 (** Returns the label of a given node *)
70
71 val data : t -> node -> string
72 (** Returns the character data associated with a node.
73     The only node having character data are those whose label is
74     QName.text, QName.cdata_section or QName.comment
75  *)
76
77 val preorder : t -> node -> int
78 (** Returns the position of a node in pre-order in the tree. The
79     root has preorder 0. [nil] has pre-order [-1].
80 *)