1 (* Copyright (C) 2000-2002, HELM Team.
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.
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.
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.
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,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
26 (* cut and paste from xml2Gdome.ml: there was the namespace problem.
27 This is a fst patch: we generate a fixed namespace for math *)
28 let document_of_xml (domImplementation : Gdome.domImplementation) strm =
29 let module G = Gdome in
31 let namespace = "http://www.w3.org/1998/Math/MathML" in
32 let root_name,root_attributes,root_content =
34 ignore (Stream.next strm) ; (* to skip the <?xml ...?> declaration *)
35 ignore (Stream.next strm) ; (* to skip the DOCTYPE declaration *)
37 match Stream.next strm with
38 X.Empty(n,l) -> n,l,[<>]
39 | X.NEmpty(n,l,c) -> n,l,c
43 domImplementation#createDocument ~namespaceURI:(Some (Gdome.domString namespace))
44 ~qualifiedName:(Gdome.domString ("m:" ^ root_name)) ~doctype:None
46 document#get_documentElement#setAttribute (Gdome.domString "xmlns:m") (Gdome.domString namespace);
47 let rec aux (node : Gdome.node) =
50 let textnode = document#createTextNode ~data:(Gdome.domString a) in
51 ignore (node#appendChild ~newChild:(textnode :> Gdome.node)) ;
53 | [< 'X.Empty(n,l) ; s >] ->
54 let element = document#createElementNS
55 ~namespaceURI:(Some (Gdome.domString namespace))
56 ~qualifiedName:(Gdome.domString ("m:" ^ n)) in
60 (try String.index n ':'
61 with Not_found -> 0) in
64 ~name:(Gdome.domString n) ~value:(Gdome.domString v)
66 let ns_label = String.sub n 0 i in
68 if ns_label = "helm" then "http://www.cs.unibo.it/helm"
69 else if ns_label = "xlink" then "http://www.w3.org/1999/xlink"
71 element#setAttributeNS
72 ~namespaceURI:(Some (Gdome.domString ns))
73 ~qualifiedName:(Gdome.domString n)
74 ~value:(Gdome.domString v)) l ;
76 (node#appendChild ~newChild:(element : Gdome.element :> Gdome.node)) ;
78 | [< 'X.NEmpty(n,l,c) ; s >] ->
79 let element = document#createElementNS
80 ~namespaceURI:(Some (Gdome.domString namespace))
81 ~qualifiedName:(Gdome.domString ("m:" ^ n)) in
85 (try String.index n ':'
86 with Not_found -> 0) in
89 ~name:(Gdome.domString n) ~value:(Gdome.domString v)
91 let ns_label = String.sub n 0 i in
93 if ns_label = "helm" then "http://www.cs.unibo.it/helm"
94 else if ns_label = "xlink" then "http://www.w3.org/1999/xlink"
96 element#setAttributeNS
97 ~namespaceURI:(Some (Gdome.domString ns))
98 ~qualifiedName:(Gdome.domString n)
99 ~value:(Gdome.domString v)) l ;
100 ignore (node#appendChild ~newChild:(element :> Gdome.node)) ;
101 aux (element :> Gdome.node) c ;
105 let root = document#get_documentElement in
106 List.iter (function (n,v) -> root#setAttribute
107 ~name:(Gdome.domString n) ~value:(Gdome.domString v)) root_attributes ;
108 aux (root : Gdome.element :> Gdome.node) root_content ;