let db_of_xml = fun xml ->
let xml =
try Dtd.prove checked_dtd "db" xml
with
| Dtd.Check_error _ -> raise Invalid_db_file
| Dtd.Prove_error _ -> raise Invalid_db_file
in
let db = SQL_db.create_empty () in
let tables = find_first_tag xml "tables"
and indexes = find_first_tag xml "indexes"
and queries = find_first_tag xml "queries"
and vtables = find_first_tag xml "vtables" in
try
List.iter
(fun t -> ignore (table_of_dtd_valid_xml db t))
(Xml.children tables);
List.iter
(fun i -> ignore (index_of_dtd_valid_xml db i))
(Xml.children indexes);
List.iter
(fun q -> ignore (query_of_dtd_valid_xml db q))
(Xml.children queries);
List.iter
(fun v -> ignore (vtable_of_dtd_valid_xml db v))
(Xml.children vtables);
db
with
| Xml.Not_pcdata _ -> Dbf_misc.ie ()
| Xml.Not_element _ -> Dbf_misc.ie ()
| Xml.No_attribute _ -> Dbf_misc.ie ()