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 (***********************************************************************)
17 Time-stamp: <Last modified on 2013-04-22 16:29:52 CEST by Kim Nguyen>
20 (** The different kind of XML nodes and utility functions *)
25 Document | Element | Text | Comment | Attribute | ProcessingInstruction | Node
29 Document -> "document"
30 | Element -> "element"
31 | Attribute -> "attribute"
33 | Comment -> "comment"
34 | ProcessingInstruction -> "processing-instruction"
37 let print ppf k = Format.fprintf ppf "%s" (to_string k)
41 k1 == Node || k2 == Node || k1 == k2
44 (** Signatures for trees *)
46 exception Parse_error of string
51 (** The type of a tree node *)
54 (** The type of trees *)
57 (** Return the number of nodes *)
60 (** Nil node, denoting the first/second child of a leaf or the parent of
64 (** Dummy node that is guaranteed to never occur in any tree *)
66 val load_xml_file : in_channel -> t
67 (** Takes a file descriptor and returns the XML data stored in the
68 corresponding file. Start at the current position in the file
69 descriptor (which is not necessarily the begining of file)
72 val load_xml_string : string -> t
73 (** Loads XML data stored in a string *)
75 val print_xml : out_channel -> t -> node -> unit
76 (** Outputs the tree as an XML document on the given output_channel *)
79 (** Returns the root of the tree *)
81 val first_child : t -> node -> node
82 (** [first_child t n] returns the first child of node [n] in tree [t].
83 Returns [nil] if [n] is a leaf. Returns [nil] if [n == nil].
86 val next_sibling : t -> node -> node
87 (** [next_sibling t n] returns the next_sibling of node [n] in tree [t].
88 Returns [nil] if [n] is the last child of a node.
89 Returns [nil] if [n == nil].
92 val parent : t -> node -> node
93 (** [next_sibling t n] returns the parent of node [n] in tree [t].
94 Returns [nil] if [n] is the root of the tree.
95 Returns [nil] if [n == nil].
98 val tag : t -> node -> QName.t
99 (** Returns the label of a given node *)
101 val data : t -> node -> string
102 (** Returns the character data associated with a node.
103 The only node having character data are those whose label is
104 QName.text, QName.cdata_section or QName.comment
107 val kind : t -> node -> NodeKind.t
108 (** Returns the kind of the given node *)
110 val preorder : t -> node -> int
111 (** Returns the position of a node in pre-order in the tree. The
112 root has preorder 0. [nil] has pre-order [-1].
115 val print_node : Format.formatter -> node -> unit