+++ /dev/null
-(* 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/.
- *)
-
-let document_of_xml (domImplementation : Gdome.domImplementation) strm =
- let module G = Gdome in
- let module X = Xml in
- let root_name,root_attributes,root_content =
- ignore (Stream.next strm) ; (* to skip the <?xml ...?> 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:None
- ~qualifiedName:(Gdome.domString root_name) ~doctype:None
- in
- 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#createElement ~tagName:(Gdome.domString n) in
- List.iter (function (n,v) -> element#setAttribute
- ~name:(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#createElement ~tagName:(Gdome.domString n) in
- List.iter
- (function (n,v) ->
- element#setAttribute ~name:(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
-;;