Mark Shinwell.
open Core
type xml =
| Element of Xmlm.tag * xml list
| Data of string
(*
let rec dump_xml = function
| Element (((_, name), _attrs), xmls) ->
Printf.eprintf "Element %s:\n" name;
dump_xmls xmls;
Printf.eprintf "Element %s ends.\n" name
| Data d -> Printf.eprintf "Data %s\n" d
and dump_xmls xmls =
List.iter xmls ~f:dump_xml
*)
let input_xml file =
let chan = In_channel.create file in
let el tag children = Element (tag, children) in
let data str = Data str in
try
let input = Xmlm.make_input (`Channel chan) in
let _dtd, xml = Xmlm.input_doc_tree ~el ~data input in
In_channel.close chan;
xml
with Xmlm.Error ((line, column), error) ->
Printf.eprintf "XML parsing error (line %d, column %d): %s\n"
line column
(Xmlm.error_message error);
failwith "Cannot parse GPX file"