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;;
10 let option_to_exception v e =
16 class o_mDOMString (str: Minidom.mDOMString) =
18 method get_dom_string = str
19 method get_string = Minidom.string_of_mDOMString str
22 let o_mDOMString_of_string str =
23 new o_mDOMString (Minidom.mDOMString_of_string str)
25 class o_mDOMEntity (ent : Minidom.mDOMEntity) =
27 method get_dom_entity = ent
29 new o_mDOMString (Minidom.entity_get_content ent)
33 class o_mDOMDoc (doc : Minidom.mDOMDoc) =
35 method get_dom_doc = doc
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) =
41 (Minidom.doc_add_entity doc
42 (name#get_dom_string) (value#get_dom_string)
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
53 and o_mDOMNode (node : Minidom.mDOMNode) =
55 method get_dom_node = node
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
62 method get_type = Minidom.node_get_type node
64 match Minidom.node_get_name node with
65 | Some x -> Some (new o_mDOMString x)
68 match Minidom.node_get_ns_uri node with
69 | Some x -> Some (new o_mDOMString x)
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)
75 method get_attribute_ns (name : o_mDOMString) (uri : o_mDOMString) =
77 Minidom.node_get_attribute_ns node
78 (name#get_dom_string) (uri#get_dom_string)
80 | Some x -> Some (new o_mDOMString x)
83 match Minidom.node_get_content node with
84 | Some x -> Some (new o_mDOMString x)
88 (option_to_exception (Minidom.node_get_parent node) Node_has_no_parent)
89 method get_prev_sibling =
92 (Minidom.node_get_prev_sibling node)
93 (Node_has_no_sibling "left")
95 method get_next_sibling =
98 (Minidom.node_get_next_sibling node)
99 (Node_has_no_sibling "right")
101 method get_first_child =
104 (Minidom.node_get_first_child node)
105 (Node_has_no_children)
107 method get_first_attribute =
110 (Minidom.node_get_first_attribute node)
111 (Node_has_no_attributes)
113 method is_first = Minidom.node_is_first node
114 method is_last = Minidom.node_is_last node
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)
121 and o_mDOMAttr (attr : Minidom.mDOMAttr) =
123 method get_dom_attr = attr
126 match Minidom.attr_get_name attr with
127 | Some x -> Some (new o_mDOMString x)
130 match Minidom.attr_get_ns_uri attr with
131 | Some x -> Some (new o_mDOMString x)
134 match Minidom.attr_get_value attr with
135 | Some x -> Some (new o_mDOMString x)
137 method get_prev_sibling =
140 (Minidom.attr_get_prev_sibling attr)
141 (Attribute_has_no_sibling "left")
143 method get_next_sibling =
146 (Minidom.attr_get_next_sibling attr)
147 (Attribute_has_no_sibling "right")
152 (Minidom.attr_get_parent attr) Attribute_has_no_parent