-exception Minidom_exception of string;;
+exception Node_has_no_parent;;
+exception Node_has_no_sibling of string;;
+exception Node_has_no_children;;
+exception Node_has_no_attributes;;
+exception Attribute_has_no_sibling of string;;
+exception Attribute_has_no_parent;;
+exception Undefined_entity;;
let option_to_exception v e =
- match (v) with
+ match v with
Some x -> x
| None -> raise e
;;
let o_mDOMString_of_string str =
new o_mDOMString (Minidom.mDOMString_of_string str)
+class o_mDOMEntity (ent : Minidom.mDOMEntity) =
+ object
+ method get_dom_entity = ent
+ method get_content =
+ new o_mDOMString (Minidom.entity_get_content ent)
+ end
+;;
+
class o_mDOMDoc (doc : Minidom.mDOMDoc) =
object
method get_dom_doc = doc
- method get_root_node = Minidom.doc_get_root_node doc
- method add_entity (name : o_mDOMString) =
- Minidom.doc_add_entity doc (name#get_dom_string)
+ method get_root_node =
+ new o_mDOMNode (Minidom.doc_get_root_node doc)
+ method add_entity (name : o_mDOMString) (value : o_mDOMString) =
+ new o_mDOMEntity
+ (Minidom.doc_add_entity doc
+ (name#get_dom_string) (value#get_dom_string)
+ )
method get_entity (name : o_mDOMString) =
- Minidom.doc_get_entity doc (name#get_dom_string)
+ match Minidom.doc_get_entity doc (name#get_dom_string) with
+ | Some x -> new o_mDOMEntity x
+ | None -> raise Undefined_entity
method get_predefined_entity (name : o_mDOMString) =
- Minidom.doc_get_predefined_entity doc (name#get_dom_string)
- end;;
-
-class o_mDOMNode (node : Minidom.mDOMNode) =
+ match Minidom.doc_get_predefined_entity doc (name#get_dom_string) with
+ | Some x -> new o_mDOMEntity x
+ | None -> raise Undefined_entity
+ end
+and o_mDOMNode (node : Minidom.mDOMNode) =
object
method get_dom_node = node
method get_type = Minidom.node_get_type node
method get_name =
- new o_mDOMString
- (option_to_exception (Minidom.node_get_name node) (Minidom_exception "node has no name"))
+ match Minidom.node_get_name node with
+ | Some x -> Some (new o_mDOMString x)
+ | None -> None
method get_ns_uri =
- new o_mDOMString
- (option_to_exception (Minidom.node_get_ns_uri node) (Minidom_exception "node has no associated namepsace"))
+ match Minidom.node_get_ns_uri node with
+ | Some x -> Some (new o_mDOMString x)
+ | None -> None
method get_attribute (name : o_mDOMString) =
- new o_mDOMString
- (option_to_exception
- (Minidom.node_get_attribute node (name#get_dom_string))
- (Minidom_exception "attribute not set for this node")
- )
+ match Minidom.node_get_attribute node (name#get_dom_string) with
+ | Some x -> Some (new o_mDOMString x)
+ | None -> None
method get_attribute_ns (name : o_mDOMString) (uri : o_mDOMString) =
- new o_mDOMString
- (option_to_exception
- (Minidom.node_get_attribute_ns node (name#get_dom_string) (uri#get_dom_string))
- (Minidom_exception "attribute not set for this node")
- )
+ match
+ Minidom.node_get_attribute_ns node
+ (name#get_dom_string) (uri#get_dom_string)
+ with
+ | Some x -> Some (new o_mDOMString x)
+ | None -> None
method get_content =
- new o_mDOMString
- (option_to_exception (Minidom.node_get_content node) (Minidom_exception "node has no content"))
+ match Minidom.node_get_content node with
+ | Some x -> Some (new o_mDOMString x)
+ | None -> None
method get_parent =
new o_mDOMNode
- (option_to_exception (Minidom.node_get_parent node) (Minidom_exception "node has no parent"))
+ (option_to_exception (Minidom.node_get_parent node) Node_has_no_parent)
method get_prev_sibling =
new o_mDOMNode
- (option_to_exception (Minidom.node_get_prev_sibling node) (Minidom_exception "node has no previous sibling"))
+ (option_to_exception
+ (Minidom.node_get_prev_sibling node)
+ (Node_has_no_sibling "left")
+ )
method get_next_sibling =
new o_mDOMNode
- (option_to_exception (Minidom.node_get_next_sibling node) (Minidom_exception "node has no next sibling"))
+ (option_to_exception
+ (Minidom.node_get_next_sibling node)
+ (Node_has_no_sibling "right")
+ )
method get_first_child =
new o_mDOMNode
- (option_to_exception (Minidom.node_get_first_child node) (Minidom_exception "node has no children"))
+ (option_to_exception
+ (Minidom.node_get_first_child node)
+ (Node_has_no_children)
+ )
method get_first_attribute =
new o_mDOMAttr
- (option_to_exception (Minidom.node_get_first_attribute node) (Minidom_exception "node has no attributes"))
+ (option_to_exception
+ (Minidom.node_get_first_attribute node)
+ (Node_has_no_attributes)
+ )
method is_first = Minidom.node_is_first node
method is_last = Minidom.node_is_last node
- method get_children = List.map (function x -> new o_mDOMNode x) (Minidom.node_get_children node)
- method get_attributes = List.map (function x -> new o_mDOMAttr x) (Minidom.node_get_attributes node)
+ method get_children =
+ List.map (function x -> new o_mDOMNode x) (Minidom.node_get_children node)
+ method get_attributes = List.map
+ (function x -> new o_mDOMAttr x) (Minidom.node_get_attributes node)
end
and o_mDOMAttr (attr : Minidom.mDOMAttr) =
object
method get_dom_attr = attr
method get_name =
- new o_mDOMString
- (option_to_exception (Minidom.attr_get_name attr) (Minidom_exception "attribute has no name"))
+ match Minidom.attr_get_name attr with
+ | Some x -> Some (new o_mDOMString x)
+ | None -> None
method get_ns_uri =
- new o_mDOMString
- (option_to_exception (Minidom.attr_get_ns_uri attr) (Minidom_exception "attribute has no associated namespace"))
+ match Minidom.attr_get_ns_uri attr with
+ | Some x -> Some (new o_mDOMString x)
+ | None -> None
method get_value =
- new o_mDOMString
- (option_to_exception (Minidom.attr_get_value attr) (Minidom_exception "attribute has no value"))
-
+ match Minidom.attr_get_value attr with
+ | Some x -> Some (new o_mDOMString x)
+ | None -> None
method get_prev_sibling =
new o_mDOMAttr
- (option_to_exception (Minidom.attr_get_prev_sibling attr) (Minidom_exception "attribute has no previous sibling"))
+ (option_to_exception
+ (Minidom.attr_get_prev_sibling attr)
+ (Attribute_has_no_sibling "left")
+ )
method get_next_sibling =
new o_mDOMAttr
- (option_to_exception (Minidom.attr_get_next_sibling attr) (Minidom_exception "attribute has no next sibling"))
+ (option_to_exception
+ (Minidom.attr_get_next_sibling attr)
+ (Attribute_has_no_sibling "right")
+ )
method get_parent =
new o_mDOMNode
- (option_to_exception (Minidom.attr_get_parent attr) (Minidom_exception "attribute has no parent"))
+ (option_to_exception
+ (Minidom.attr_get_parent attr) Attribute_has_no_parent
+ )
end
;;