X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2FDEVEL%2Fmlminidom%2Ftest.ml;fp=helm%2FDEVEL%2Fmlminidom%2Ftest.ml;h=1a239f8f60abc13b97cf683720d168a84b6a0b80;hb=d70d5de1ec9ccc86c9df45036245af34c37575ea;hp=0000000000000000000000000000000000000000;hpb=99d60351f793983bb7633334ea59e95feb36c72c;p=helm.git diff --git a/helm/DEVEL/mlminidom/test.ml b/helm/DEVEL/mlminidom/test.ml new file mode 100644 index 000000000..1a239f8f6 --- /dev/null +++ b/helm/DEVEL/mlminidom/test.ml @@ -0,0 +1,104 @@ +(* Copyright (C) 2000, Luca Padovani . + * + * This file is part of mlminidom, the Ocaml binding for minidom. + * + * mlminidom 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. + * + * mlminidom 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 mlminidom; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * For details, send a mail to the author. + *) + +let doc = Minidom.doc_load "test.xml" + +let root = Minidom.doc_get_root_node doc + +let check_attribute_ns attr = + Printf.printf "\n\n"; + let ns_uri = Minidom.attr_get_ns_uri attr + and attr_name = Minidom.attr_get_name attr + and attr_value = Minidom.attr_get_value attr + and parent = Minidom.attr_get_parent attr + in + match parent,ns_uri,attr_name,attr_value with + Some parent_node,Some uri,Some attribute_name,Some attribute_value -> + let attr_value = Minidom.node_get_attribute_ns parent_node attribute_name uri + in begin + match attr_value with + Some attr1 -> + Printf.printf "found the attribute with ns %s (was %s)\n" + (Minidom.string_of_mDOMString attr1) (Minidom.string_of_mDOMString attribute_value) + | None -> + Printf.printf "attribute not found (uri was %s)!!!!\n" (Minidom.string_of_mDOMString uri) + end + | _ -> + Printf.printf "parent_node == NULL || uri == NULL || attribute_name == NULL || attribute_value == NULL\n" +;; + +let print_attribute attr = + check_attribute_ns attr; + let ns_uri = Minidom.attr_get_ns_uri attr + in + begin + match ns_uri with + Some uri -> Printf.printf " %s:" (Minidom.string_of_mDOMString uri); + | None -> () + end; + match ((Minidom.attr_get_name attr), (Minidom.attr_get_value attr)) with + (Some attr_name, Some attr_value) -> + Printf.printf " %s=\"%s\"" (Minidom.string_of_mDOMString attr_name) (Minidom.string_of_mDOMString attr_value) + | (Some attr_name, _) -> + Printf.printf " ??? attribute %s has no value !!!" (Minidom.string_of_mDOMString attr_name) + | (_,_) -> + Printf.printf " ??? very strange attribute !!!" +;; + +let rec print_node n node = + if Minidom.node_is_blank node then () + else if Minidom.node_is_element node then begin + match Minidom.node_get_name node with + Some node_name -> + begin + let children = Minidom.node_get_children node + and attributes = Minidom.node_get_attributes node + and ns_uri = Minidom.node_get_ns_uri node + and is_first,is_last = (Minidom.node_is_first node), (Minidom.node_is_last node) + in + for i = 1 to n do print_char ' ' done; + Printf.printf "<"; + begin + match ns_uri with + Some uri -> Printf.printf "%s:" (Minidom.string_of_mDOMString uri) + | None -> () + end; + Printf.printf "%s" (Minidom.string_of_mDOMString node_name); + List.iter print_attribute attributes; + Printf.printf ">\n"; + List.iter (print_node (n + 2)) children; + for i = 1 to n do print_char ' ' done; + Printf.printf "\n" (Minidom.string_of_mDOMString node_name) + end + | None -> Printf.printf "??? this node has no name !!!\n" + end else if Minidom.node_is_text node then begin + match Minidom.node_get_content node with + Some node_content -> + for i = 1 to n do print_char ' ' done; + Printf.printf "%s\n" (Minidom.string_of_mDOMString node_content) + | None -> Printf.printf "??? this node has no content !!!\n" + end else begin + Printf.printf "don't know how to manage a node with type %d\n" (Minidom.node_get_type node) + end +;; + +print_node 0 root;; +