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 | ProcessingInstruction | Node
25 Document -> "document"
26 | Element -> "element"
27 | Attribute -> "attribute"
29 | Comment -> "comment"
30 | ProcessingInstruction -> "processing-instruction"
33 let print ppf k = Format.fprintf ppf "%s" (to_string k)
37 k1 == Node || k2 == Node || k1 == k2
40 (** Signatures for trees *)
42 exception Parse_error of string
47 (** The type of a tree node *)
50 (** The type of trees *)
53 (** Return the number of nodes *)
56 (** Nil node, denoting the first/second child of a leaf or the parent of
60 (** Dummy node that is guaranteed to never occur in any tree *)
62 val load_xml_file : in_channel -> t
63 (** Takes a file descriptor and returns the XML data stored in the
64 corresponding file. Start at the current position in the file
65 descriptor (which is not necessarily the begining of file)
68 val load_xml_string : string -> t
69 (** Loads XML data stored in a string *)
71 val print_xml : out_channel -> t -> node -> unit
72 (** Outputs the tree as an XML document on the given output_channel *)
75 (** Returns the root of the tree *)
77 val first_child : t -> node -> node
78 (** [first_child t n] returns the first child of node [n] in tree [t].
79 Returns [nil] if [n] is a leaf. Returns [nil] if [n == nil].
82 val next_sibling : t -> node -> node
83 (** [next_sibling t n] returns the next_sibling of node [n] in tree [t].
84 Returns [nil] if [n] is the last child of a node.
85 Returns [nil] if [n == nil].
88 val parent : t -> node -> node
89 (** [next_sibling t n] returns the parent of node [n] in tree [t].
90 Returns [nil] if [n] is the root of the tree.
91 Returns [nil] if [n == nil].
94 val tag : t -> node -> QName.t
95 (** Returns the label of a given node *)
97 val data : t -> node -> string
98 (** Returns the character data associated with a node.
99 The only node having character data are those whose label is
100 QName.text, QName.cdata_section or QName.comment
103 val kind : t -> node -> NodeKind.t
104 (** Returns the kind of the given node *)
106 val preorder : t -> node -> int
107 (** [preorder t n] returns the pre-order position of [n] in [t].
108 [preodrder t (root t) == 0] and [preorder t nil < 0].
110 val print_node : Format.formatter -> node -> unit