]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/lablgtk_gtkmathview/lablgtk-20001129_gtkmathview-0.2.1/minidom/ominidom.ml
Initial revision
[helm.git] / helm / DEVEL / lablgtk_gtkmathview / lablgtk-20001129_gtkmathview-0.2.1 / minidom / ominidom.ml
1
2 exception Node_has_no_parent;;
3 exception Node_has_no_sibling of string;;
4 exception Node_has_no_children;;
5 exception Node_has_no_attributes;;
6 exception Attribute_has_no_sibling of string;;
7 exception Attribute_has_no_parent;;
8 exception Undefined_entity;;
9
10 let option_to_exception v e =
11   match v with
12     Some x -> x
13   | None   -> raise e
14 ;;
15
16 class o_mDOMString (str: Minidom.mDOMString) =
17   object
18     method get_dom_string = str
19     method get_string = Minidom.string_of_mDOMString str
20   end;;
21   
22 let o_mDOMString_of_string str =
23   new o_mDOMString (Minidom.mDOMString_of_string str)
24
25 class o_mDOMEntity (ent : Minidom.mDOMEntity) =
26   object
27     method get_dom_entity = ent
28     method get_content =
29       new o_mDOMString (Minidom.entity_get_content ent)
30   end
31 ;;
32
33 class o_mDOMDoc (doc : Minidom.mDOMDoc) =
34   object
35     method get_dom_doc = doc
36
37     method get_root_node =
38       new o_mDOMNode (Minidom.doc_get_root_node doc)
39     method add_entity (name : o_mDOMString) (value : o_mDOMString) =
40       new o_mDOMEntity
41         (Minidom.doc_add_entity doc
42           (name#get_dom_string) (value#get_dom_string)
43         )
44     method get_entity (name : o_mDOMString) =
45       match Minidom.doc_get_entity doc (name#get_dom_string) with
46       | Some x -> new o_mDOMEntity x
47       | None -> raise Undefined_entity
48     method get_predefined_entity (name : o_mDOMString) =
49       match Minidom.doc_get_predefined_entity doc (name#get_dom_string) with
50       | Some x -> new o_mDOMEntity x
51       | None -> raise Undefined_entity
52   end
53 and o_mDOMNode (node : Minidom.mDOMNode) =
54   object
55     method get_dom_node = node
56
57     method is_text = Minidom.node_is_text node
58     method is_element = Minidom.node_is_element node
59     method is_blank = Minidom.node_is_blank node
60     method is_entity_ref = Minidom.node_is_entity_ref node
61
62     method get_type = Minidom.node_get_type node
63     method get_name = 
64       match Minidom.node_get_name node with
65       | Some x -> Some (new o_mDOMString x)
66       | None   -> None
67     method get_ns_uri =
68       match Minidom.node_get_ns_uri node with
69       | Some x -> Some (new o_mDOMString x)
70       | None   -> None
71     method get_attribute (name : o_mDOMString) =
72       match Minidom.node_get_attribute node (name#get_dom_string) with
73       | Some x -> Some (new o_mDOMString x)
74       | None   -> None
75     method get_attribute_ns (name : o_mDOMString) (uri : o_mDOMString) =
76       match 
77         Minidom.node_get_attribute_ns node
78           (name#get_dom_string) (uri#get_dom_string)
79       with
80       | Some x -> Some (new o_mDOMString x)
81       | None   -> None
82     method get_content =
83       match Minidom.node_get_content node with
84       | Some x -> Some (new o_mDOMString x)
85       | None   -> None
86     method get_parent =
87       new o_mDOMNode
88         (option_to_exception (Minidom.node_get_parent node) Node_has_no_parent)
89     method get_prev_sibling =
90       new o_mDOMNode
91         (option_to_exception
92          (Minidom.node_get_prev_sibling node)
93          (Node_has_no_sibling "left")
94         )
95     method get_next_sibling =
96       new o_mDOMNode
97         (option_to_exception
98          (Minidom.node_get_next_sibling node)
99          (Node_has_no_sibling "right")
100         )
101     method get_first_child =
102       new o_mDOMNode
103         (option_to_exception
104          (Minidom.node_get_first_child node)
105          (Node_has_no_children)
106         )
107     method get_first_attribute =
108       new o_mDOMAttr
109         (option_to_exception
110           (Minidom.node_get_first_attribute node)
111           (Node_has_no_attributes)
112         )
113     method is_first = Minidom.node_is_first node
114     method is_last = Minidom.node_is_last node
115
116     method get_children =
117       List.map (function x -> new o_mDOMNode x) (Minidom.node_get_children node)
118     method get_attributes = List.map
119       (function x -> new o_mDOMAttr x) (Minidom.node_get_attributes node)
120   end
121 and o_mDOMAttr (attr : Minidom.mDOMAttr) =
122   object
123     method get_dom_attr = attr
124
125     method get_name =
126       match Minidom.attr_get_name attr with
127       | Some x -> Some (new o_mDOMString x)
128       | None   -> None
129     method get_ns_uri =
130       match Minidom.attr_get_ns_uri attr with
131       | Some x -> Some (new o_mDOMString x)
132       | None   -> None
133     method get_value =
134       match Minidom.attr_get_value attr with
135       | Some x -> Some (new o_mDOMString x)
136       | None   -> None
137     method get_prev_sibling =
138       new o_mDOMAttr
139         (option_to_exception
140           (Minidom.attr_get_prev_sibling attr)
141           (Attribute_has_no_sibling "left")
142         )
143     method get_next_sibling =
144       new o_mDOMAttr
145         (option_to_exception
146           (Minidom.attr_get_next_sibling attr)
147           (Attribute_has_no_sibling "right")
148         )
149     method get_parent =
150       new o_mDOMNode
151         (option_to_exception
152           (Minidom.attr_get_parent attr) Attribute_has_no_parent
153         )
154   end
155 ;;
156