]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/xml/xmlPushParser.mli
ocaml 3.09 transition
[helm.git] / helm / ocaml / xml / xmlPushParser.mli
1 (* Copyright (C) 2004-2005, HELM Team.
2  * 
3  * This file is part of HELM, an Hypertextual, Electronic
4  * Library of Mathematics, developed at the Computer Science
5  * Department, University of Bologna, Italy.
6  * 
7  * HELM is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  * 
12  * HELM is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with HELM; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://helm.cs.unibo.it/
24  *)
25
26 (** {2 XLM push parser generic interface}
27  * Do not depend on CIC *)
28
29   (** callbacks needed to instantiate a parser *)
30 type callbacks = {
31   start_element:
32     (string -> (string * string) list -> unit) option;  (* tag, attr list *)
33   end_element: (string -> unit) option;                 (* tag *)
34   character_data: (string -> unit) option;              (* data *)
35   processing_instruction:
36     (string -> string -> unit) option;                  (* target, value *)
37   comment: (string -> unit) option;                     (* value *)
38 }
39
40   (** do nothing callbacks (all set to None) *)
41 val default_callbacks: callbacks
42
43   (** source from which parse an XML file *)
44 type xml_source =
45   [ `Channel of in_channel
46   | `File of string
47   | `Gzip_channel of Gzip.in_channel
48   | `Gzip_file of string
49   | `String of string
50   ]
51
52   (** source position in a XML source.
53    * A position is a pair <line, column> *)
54 type position = int * int
55
56 type xml_parser
57
58   (** raised when a parse error occurs, argument is an error message.
59    * This exception carries no position information, but it should be get using
60    * get_position below *)
61 exception Parse_error of string
62
63   (** Create a push parser which invokes the given callbacks *)
64 val create_parser: callbacks -> xml_parser
65
66   (** Parse XML data from a given source with a given parser
67     * @raise Parse_error *)
68 val parse: xml_parser -> xml_source -> unit
69
70   (** Inform the parser that parsing is completed, needed only when source is
71    * `String, for other sources it is automatically invoked when the end of file
72    * is reached
73    * @raise Parse_error *)
74 val final: xml_parser -> unit
75
76   (** @return current <line, column> pair *)
77 val get_position: xml_parser -> position
78