1 /* Copyright (C) 2000, Luca Padovani <luca.padovani@cs.unibo.it>.
3 * This file is part of mlminidom, the Ocaml binding for minidom.
5 * mlminidom is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * mlminidom is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with mlminidom; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 * For details, send a mail to the author.
28 #define Val_ptr(p) ((value) (p))
29 #define Val_option(p,f) ((p != NULL) ? ml_some(f(p)) : Val_unit)
30 #define Val_mDOMString(s) (copy_string((char*) (s)))
31 #define mDOMString_val(v) ((mDOMStringRef) String_val(v))
37 value ret = alloc_small(1,0);
43 ml_string_of_mDOMString(value s)
50 ml_mDOMString_of_string(value s)
57 ml_doc_load(value file_name)
61 CAMLparam1(file_name);
63 doc_ref = mdom_load(String_val(file_name), FALSE, NULL);
64 if (doc_ref == NULL) failwith("minidom: could not load document");
66 CAMLreturn((value) doc_ref);
70 ml_doc_unload(value doc)
74 mdom_unload((mDOMDocRef) doc);
86 doc_ref = mdom_doc_new(mDOMString_val(s));
87 if (doc_ref == NULL) failwith("minidom: could not create new document");
89 CAMLreturn((value) doc_ref);
94 ml_doc_get_root_node(value doc)
99 root = mdom_doc_get_root_node((mDOMDocRef) doc);
100 if (root == NULL) failwith("minidom: document has no root node!");
102 CAMLreturn((value) root);
106 ml_doc_add_entity(value doc, value name, value content)
110 CAMLparam3(doc, name, content);
111 ent = mdom_doc_add_entity((mDOMDocRef) doc, mDOMString_val(name), mDOMString_val(content));
112 if (ent == NULL) failwith("minidom: could not add entity");
114 CAMLreturn((value) ent);
118 ml_doc_get_entity(value doc, value name)
122 CAMLparam2(doc, name);
123 ent = mdom_doc_get_entity((mDOMDocRef) doc, mDOMString_val(name));
125 CAMLreturn(Val_option(ent, Val_ptr));
129 ml_doc_get_predefined_entity(value name)
134 ent = mdom_get_predefined_entity(mDOMString_val(name));
136 CAMLreturn(Val_option(ent, Val_ptr));
140 ml_entity_get_content(value ent)
143 CAMLreturn(Val_mDOMString(mdom_entity_get_content((mDOMEntityRef) ent)));
147 ml_node_is_text(value node)
150 CAMLreturn(Val_bool(mdom_node_is_text((mDOMNodeRef) node)));
154 ml_node_is_element(value node)
157 CAMLreturn(Val_bool(mdom_node_is_element((mDOMNodeRef) node)));
161 ml_node_is_blank(value node)
164 CAMLreturn(Val_bool(mdom_node_is_blank((mDOMNodeRef) node)));
168 ml_node_is_entity_ref(value node)
171 CAMLreturn(Val_bool(mdom_node_is_entity_ref((mDOMNodeRef) node)));
175 ml_node_get_type(value node)
178 CAMLreturn(Val_int(mdom_node_get_type((mDOMNodeRef) node)));
182 ml_node_get_name(value node)
185 CAMLreturn(Val_option(mdom_node_get_name((mDOMNodeRef) node), Val_mDOMString));
189 ml_node_get_content(value node)
192 CAMLreturn(Val_option(mdom_node_get_content((mDOMNodeRef) node), Val_mDOMString));
196 ml_node_get_ns_uri(value node)
199 CAMLreturn(Val_option(mdom_node_get_ns_uri((mDOMNodeRef) node), Val_mDOMString));
203 ml_node_get_attribute(value node, value name)
205 CAMLparam2(node,name);
206 CAMLreturn(Val_option(mdom_node_get_attribute((mDOMNodeRef) node, String_val(name)), Val_mDOMString));
210 ml_node_get_attribute_ns(value node, value name, value ns_uri)
212 CAMLparam2(node,name);
213 CAMLreturn(Val_option(mdom_node_get_attribute_ns((mDOMNodeRef) node,
215 String_val(ns_uri)), Val_mDOMString));
219 ml_node_get_parent(value node)
222 CAMLreturn(Val_option(mdom_node_get_parent((mDOMNodeRef) node), Val_ptr));
226 ml_node_get_prev_sibling(value node)
229 CAMLreturn(Val_option(mdom_node_get_prev_sibling((mDOMNodeRef) node), Val_ptr));
233 ml_node_get_next_sibling(value node)
236 CAMLreturn(Val_option(mdom_node_get_next_sibling((mDOMNodeRef) node), Val_ptr));
240 ml_node_get_first_child(value node)
243 CAMLreturn(Val_option(mdom_node_get_first_child((mDOMNodeRef) node), Val_ptr));
247 ml_node_get_first_attribute(value node)
250 CAMLreturn(Val_option(mdom_node_get_first_attribute((mDOMNodeRef) node), Val_ptr));
254 ml_node_is_first(value node)
257 CAMLreturn(Val_bool(mdom_node_is_first((mDOMNodeRef) node)));
261 ml_node_is_last(value node)
264 CAMLreturn(Val_bool(mdom_node_is_last((mDOMNodeRef) node)));
268 ml_attr_get_name(value attr)
271 CAMLreturn(Val_option(mdom_attr_get_name((mDOMAttrRef) attr), Val_mDOMString));
275 ml_attr_get_ns_uri(value attr)
278 CAMLreturn(Val_option(mdom_attr_get_ns_uri((mDOMAttrRef) attr), Val_mDOMString));
282 ml_attr_get_value(value attr)
285 CAMLreturn(Val_option(mdom_attr_get_value((mDOMAttrRef) attr), Val_mDOMString));
289 ml_attr_get_prev_sibling(value attr)
292 CAMLreturn(Val_option(mdom_attr_get_prev_sibling((mDOMAttrRef) attr), Val_ptr));
296 ml_attr_get_next_sibling(value attr)
299 CAMLreturn(Val_option(mdom_attr_get_next_sibling((mDOMAttrRef) attr), Val_ptr));
303 ml_attr_get_parent(value attr)
306 CAMLreturn(Val_option(mdom_attr_get_parent((mDOMAttrRef) attr), Val_ptr));