X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;ds=sidebyside;f=helm%2Focaml%2Fcic_transformations%2Fxml2Gdomexmath.ml;fp=helm%2Focaml%2Fcic_transformations%2Fxml2Gdomexmath.ml;h=0b2db0d99c0c549261460572eb1f259b49a6ebc4;hb=f7b2e35a7bdadb4fdf0e640428e694703ddf67a5;hp=0000000000000000000000000000000000000000;hpb=70f855932359e26ca89deb11c22f9c9d26154827;p=helm.git diff --git a/helm/ocaml/cic_transformations/xml2Gdomexmath.ml b/helm/ocaml/cic_transformations/xml2Gdomexmath.ml new file mode 100644 index 000000000..0b2db0d99 --- /dev/null +++ b/helm/ocaml/cic_transformations/xml2Gdomexmath.ml @@ -0,0 +1,111 @@ +(* Copyright (C) 2000-2002, HELM Team. + * + * This file is part of HELM, an Hypertextual, Electronic + * Library of Mathematics, developed at the Computer Science + * Department, University of Bologna, Italy. + * + * HELM is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * HELM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with HELM; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, + * MA 02111-1307, USA. + * + * For details, see the HELM World-Wide-Web page, + * http://cs.unibo.it/helm/. + *) + +(* cut and paste from xml2Gdome.ml: there was the namespace problem. + This is a fst patch: we generate a fixed namespace for math *) +let document_of_xml (domImplementation : Gdome.domImplementation) strm = + let module G = Gdome in + let module X = Xml in + let namespace = "http://www.w3.org/1998/Math/MathML" in + let root_name,root_attributes,root_content = + (* + ignore (Stream.next strm) ; (* to skip the declaration *) + ignore (Stream.next strm) ; (* to skip the DOCTYPE declaration *) + *) + match Stream.next strm with + X.Empty(n,l) -> n,l,[<>] + | X.NEmpty(n,l,c) -> n,l,c + | _ -> assert false + in + let document = + domImplementation#createDocument ~namespaceURI:(Some (Gdome.domString namespace)) + ~qualifiedName:(Gdome.domString ("m:" ^ root_name)) ~doctype:None + in + document#get_documentElement#setAttribute (Gdome.domString "xmlns:m") (Gdome.domString namespace); + let rec aux (node : Gdome.node) = + parser + [< 'X.Str a ; s >] -> + let textnode = document#createTextNode ~data:(Gdome.domString a) in + ignore (node#appendChild ~newChild:(textnode :> Gdome.node)) ; + aux node s + | [< 'X.Empty(n,l) ; s >] -> + let element = document#createElementNS + ~namespaceURI:(Some (Gdome.domString namespace)) + ~qualifiedName:(Gdome.domString ("m:" ^ n)) in + List.iter + (function (n,v) -> + let i = + (try String.index n ':' + with Not_found -> 0) in + if i = 0 then + element#setAttribute + ~name:(Gdome.domString n) ~value:(Gdome.domString v) + else + let ns_label = String.sub n 0 i in + let ns = + if ns_label = "helm" then "http://www.cs.unibo.it/helm" + else if ns_label = "xlink" then "http://www.w3.org/1999/xlink" + else assert false in + element#setAttributeNS + ~namespaceURI:(Some (Gdome.domString ns)) + ~qualifiedName:(Gdome.domString n) + ~value:(Gdome.domString v)) l ; + ignore + (node#appendChild ~newChild:(element : Gdome.element :> Gdome.node)) ; + aux node s + | [< 'X.NEmpty(n,l,c) ; s >] -> + let element = document#createElementNS + ~namespaceURI:(Some (Gdome.domString namespace)) + ~qualifiedName:(Gdome.domString ("m:" ^ n)) in + List.iter + (function (n,v) -> + let i = + (try String.index n ':' + with Not_found -> 0) in + if i = 0 then + element#setAttribute + ~name:(Gdome.domString n) ~value:(Gdome.domString v) + else + let ns_label = String.sub n 0 i in + let ns = + if ns_label = "helm" then "http://www.cs.unibo.it/helm" + else if ns_label = "xlink" then "http://www.w3.org/1999/xlink" + else assert false in + element#setAttributeNS + ~namespaceURI:(Some (Gdome.domString ns)) + ~qualifiedName:(Gdome.domString n) + ~value:(Gdome.domString v)) l ; + ignore (node#appendChild ~newChild:(element :> Gdome.node)) ; + aux (element :> Gdome.node) c ; + aux node s + | [< >] -> () + in + let root = document#get_documentElement in + List.iter (function (n,v) -> root#setAttribute + ~name:(Gdome.domString n) ~value:(Gdome.domString v)) root_attributes ; + aux (root : Gdome.element :> Gdome.node) root_content ; + document +;; +