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-04 18:40:39 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
45 (** Signatures for trees *)
50 (** The type of a tree node *)
53 (** The type of trees *)
56 (** Return the number of nodes *)
59 (** Nil node, denoting the first/second child of a leaf or the parent of
63 (** Dummy node that is guaranteed to never occur in any tree *)
65 val load_xml_file : in_channel -> t
66 (** Takes a file descriptor and returns the XML data stored in the
67 corresponding file. Start at the current position in the file
68 descriptor (which is not necessarily the begining of file)
71 val load_xml_string : string -> t
72 (** Loads XML data stored in a string *)
74 val print_xml : out_channel -> t -> node -> unit
75 (** Outputs the tree as an XML document on the given output_channel *)
78 (** Returns the root of the tree *)
80 val first_child : t -> node -> node
81 (** [first_child t n] returns the first child of node [n] in tree [t].
82 Returns [nil] if [n] is a leaf. Returns [nil] if [n == nil].
85 val next_sibling : t -> node -> node
86 (** [next_sibling t n] returns the next_sibling of node [n] in tree [t].
87 Returns [nil] if [n] is the last child of a node.
88 Returns [nil] if [n == nil].
91 val parent : t -> node -> node
92 (** [next_sibling t n] returns the parent of node [n] in tree [t].
93 Returns [nil] if [n] is the root of the tree.
94 Returns [nil] if [n == nil].
97 val tag : t -> node -> QName.t
98 (** Returns the label of a given node *)
100 val data : t -> node -> string
101 (** Returns the character data associated with a node.
102 The only node having character data are those whose label is
103 QName.text, QName.cdata_section or QName.comment
106 val kind : t -> node -> NodeKind.t
107 (** Returns the kind of the given node *)
109 val preorder : t -> node -> int
110 (** Returns the position of a node in pre-order in the tree. The
111 root has preorder 0. [nil] has pre-order [-1].
114 val print_node : Format.formatter -> node -> unit