1 (***********************************************************************)
5 (* Kim Nguyen, LRI UMR8623 *)
6 (* Université Paris-Sud & CNRS *)
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 *)
14 (***********************************************************************)
16 (** The different kind of XML nodes and utility functions *)
21 Document | Element | Text | Comment | Attribute
22 | ProcessingInstruction | Node
26 Document -> "document"
27 | Element -> "element"
28 | Attribute -> "attribute"
30 | Comment -> "comment"
31 | ProcessingInstruction -> "processing-instruction"
34 let print ppf k = Format.fprintf ppf "%s" (to_string k)
38 k1 == Node || k2 == Node || k1 == k2
41 (** Signatures for trees *)
43 exception Parse_error of string
48 (** The type of a tree node *)
51 (** The type of trees *)
54 (** Return the number of nodes *)
57 (** Nil node, denoting the first/second child of a leaf or the parent of
61 (** Dummy node that is guaranteed to never occur in any tree *)
63 val load_xml_file : in_channel -> t
64 (** Takes a file descriptor and returns the XML data stored in the
65 corresponding file. Start at the current position in the file
66 descriptor (which is not necessarily the begining of file)
69 val load_xml_string : string -> t
70 (** Loads XML data stored in a string *)
72 val print_xml : out_channel -> t -> node -> unit
73 (** Outputs the tree as an XML document on the given output_channel *)
76 (** Returns the root of the tree *)
78 val first_child : t -> node -> node
79 (** [first_child t n] returns the first child of node [n] in tree [t].
80 Returns [nil] if [n] is a leaf. Returns [nil] if [n == nil].
83 val next_sibling : t -> node -> node
84 (** [next_sibling t n] returns the next_sibling of node [n] in tree [t].
85 Returns [nil] if [n] is the last child of a node.
86 Returns [nil] if [n == nil].
89 val parent : t -> node -> node
90 (** [next_sibling t n] returns the parent of node [n] in tree [t].
91 Returns [nil] if [n] is the root of the tree.
92 Returns [nil] if [n == nil].
95 val tag : t -> node -> QName.t
96 (** Returns the label of a given node *)
98 val data : t -> node -> string
99 (** Returns the character data associated with a node.
100 The only node having character data are those whose label is
101 QName.text, QName.cdata_section or QName.comment
104 val kind : t -> node -> NodeKind.t
105 (** Returns the kind of the given node *)
107 val preorder : t -> node -> int
108 (** [preorder t n] returns the pre-order position of [n] in [t].
109 [preodrder t (root t) == 0] and [preorder t nil < 0].
112 val by_preorder : t -> int -> node
113 (** [by_preorder t i] returns the node with preorder [i]
115 val print_node : Format.formatter -> node -> unit
117 val is_first_child : t -> node -> bool
118 val is_next_sibling : t -> node -> bool
119 val prev_sibling : t -> node -> node
120 (** [prev_sibling t n] returns the previous_sibling of node [n] in tree [t].
121 Returns [nil] if [n] is the first child of a node.
123 val parent_of_first : t -> node -> node
124 (** [parent_of_first t n] returns the parent of node [n] in tree [t] .
125 Returns [nil] if [n] isn't the first child of a node.