Package: libgdome2-ocaml-dev
Version: 0.2.3-2
Severity: wishlist
Tags: patch

After submitting the bug report, I've tried to add the functionality. Based on 
the parallel functions without Enc, I found the addition is quite 
straightforward.

The following statements work for me:

di#saveDocumentToFileEnc ~doc:doc2 ~name:fn2 ~encoding:"GB18030" ~indent:true 
();
di#saveDocumentToFileEnc ~doc:doc2 ~name:fn2 ~encoding:"UTF-8" ~indent:true 
();

Please find attached the patch for this. 

Since the patch has been manually edited, please let me know if it does not 
work for you.
--- gmetadom-0.2.3.orig/src/gdome_caml/iDOMImplementation.ml	2003-09-13 22:14:42.000000000 +0800
+++ gmetadom-0.2.3/src/gdome_caml/iDOMImplementation.ml	2005-11-28 15:37:39.000000000 +0800
@@ -65,6 +65,11 @@
 let saveDocumentToFile ~this ~doc ~name ?(indent=false) () =
  raw_saveDocumentToFile ~this ~doc ~name ~mode:(if indent then 1 else 0)
 ;;
+  
+external raw_saveDocumentToFileEnc : this:TDOMImplementation.t -> doc:[> `Document] GdomeT.t -> name:string -> encoding:string -> mode:int -> bool = "ml_gdome_di_saveDocumentToFileEnc"
+let saveDocumentToFileEnc ~this ~doc ~name ~encoding ?(indent=false) () =
+ raw_saveDocumentToFileEnc ~this ~doc ~name ~encoding ~mode:(if indent then 1 else 0)
+;;
 
 external raw_saveDocumentToMemory :
   this:TDOMImplementation.t ->
@@ -76,6 +81,17 @@
  raw_saveDocumentToMemory ~this ~doc ~mode:(if indent then 1 else 0)
 ;;
 
+external raw_saveDocumentToMemoryEnc :
+  this:TDOMImplementation.t ->
+  doc:[> `Document] GdomeT.t ->
+  encoding:string
+  mode:int ->
+  string = "ml_gdome_di_saveDocumentToMemoryEnc"
+
+let saveDocumentToMemoryEnc ~this ~doc ~encoding ?(indent=false) () =
+ raw_saveDocumentToMemoryEnc ~this ~doc ~encoding ~mode:(if indent then 1 else 0)
+;;
+
 external enableEvent :
   this:TDOMImplementation.t ->
   doc:[> `Document] GdomeT.t ->
--- gmetadom-0.2.3.orig/src/gdome_caml/iDOMImplementation.mli	2003-09-13 22:14:42.000000000 +0800
+++ gmetadom-0.2.3/src/gdome_caml/iDOMImplementation.mli	2005-11-28 15:38:50.000000000 +0800
@@ -50,12 +50,22 @@
   this:TDOMImplementation.t ->
   doc:[> `Document] GdomeT.t -> name:string ->
   ?indent:bool -> unit -> bool
+  
+val saveDocumentToFileEnc :
+  this:TDOMImplementation.t ->
+  doc:[> `Document] GdomeT.t -> name:string -> encoding:string ->
+  ?indent:bool -> unit -> bool
 
 val saveDocumentToMemory :
   this:TDOMImplementation.t ->
   doc:[> `Document] GdomeT.t ->
   ?indent:bool -> unit -> string
 
+val saveDocumentToMemoryEnc :
+  this:TDOMImplementation.t ->
+  doc:[> `Document] GdomeT.t -> encoding:string ->
+  ?indent:bool -> unit -> string
+
 val enableEvent :
   this:TDOMImplementation.t ->
   doc:[> `Document] GdomeT.t ->
--- gmetadom-0.2.3.orig/src/gdome_caml/ml_DOMImplementation.c	2003-09-13 22:14:42.000000000 +0800
+++ gmetadom-0.2.3/src/gdome_caml/ml_DOMImplementation.c	2005-11-28 15:33:51.000000000 +0800
@@ -143,6 +143,17 @@
 }
 
 value
+ml_gdome_di_saveDocumentToFileEnc(value self, value doc, value name, value encoding, value mode)
+{
+  CAMLparam5(self, doc, name, encoding, mode);
+  GdomeException exc_;
+  GdomeBoolean res_;
+  res_ = gdome_di_saveDocToFileEnc(DOMImplementation_val(self), Document_val(doc), String_val(name), String_val(encoding), Int_val(mode), &exc_);
+  if (exc_ != 0) throw_exception(exc_, "DOMImplementation.saveDocToFileEnc");
+  CAMLreturn(Val_bool(res_));
+}
+
+value
 ml_gdome_di_saveDocumentToMemory(value self, value doc, value mode)
 {
   CAMLparam3(self, doc, mode);
@@ -178,6 +189,42 @@
 }
 
 value
+ml_gdome_di_saveDocumentToMemoryEnc(value self, value doc, value encoding, value mode)
+{
+  CAMLparam4(self, doc, encoding, mode);
+  GdomeException exc_;
+  char *c_string = NULL;
+  CAMLlocal1(caml_string);
+  gdome_di_saveDocToMemoryEnc(DOMImplementation_val(self),
+			      Document_val(doc),
+			      &c_string,
+			      String_val(encoding),
+			      Int_val(mode),
+			      &exc_);
+  /*
+   * ### XXX The buffer returned by gdome_di_saveDocToMemory should
+   * really be freed using a GDome function that calls the free() from
+   * the DOM library that allocated the buffer.  For now, just use
+   * free(), since libxml2 normally uses malloc() to allocate the
+   * memory.
+   */
+#define my_free free
+
+  if (exc_ != 0) {
+    if (c_string) {
+      my_free(c_string);
+    }
+    throw_exception(exc_, "DOMImplementation.saveDocToMemoryEnc");
+  }
+  if (!c_string) raise_out_of_memory();
+  caml_string = copy_string(c_string);
+
+  my_free(c_string);
+
+  CAMLreturn(caml_string);
+}
+
+value
 ml_gdome_di_enableEvent(value self, value doc, value name)
 {
   CAMLparam3(self, doc, name);
--- gmetadom-0.2.3.orig/src/gdome_caml/ocaml/gdome.ml	2005-07-07 17:19:42.000000000 +0800
+++ gmetadom-0.2.3/src/gdome_caml/ocaml/gdome.ml	2005-11-28 15:41:46.000000000 +0800
@@ -45,8 +45,12 @@
   method createDocumentFromMemory ~doc ?validatingMode ?keepEntities () = new document (IDOMImplementation.createDocumentFromMemory ~this:obj ~doc:((doc : domString)#as_DOMString) ?validatingMode ?keepEntities ())
   method saveDocumentToFile ~(doc : document) =
    IDOMImplementation.saveDocumentToFile ~this:obj ~doc:((doc : document)#as_Document)
+  method saveDocumentToFileEnc ~(doc : document) =
+   IDOMImplementation.saveDocumentToFileEnc ~this:obj ~doc:((doc : document)#as_Document)
  method saveDocumentToMemory ~(doc : document) =
   IDOMImplementation.saveDocumentToMemory ~this:obj ~doc:((doc : document)#as_Document)
+ method saveDocumentToMemoryEnc ~(doc : document) =
+  IDOMImplementation.saveDocumentToMemoryEnc ~this:obj ~doc:((doc : document)#as_Document)
  method enableEvent ~doc ~name = IDOMImplementation.enableEvent ~this:obj ~doc:((doc : document)#as_Document) ~name
  method disableEvent ~doc ~name = IDOMImplementation.disableEvent ~this:obj ~doc:((doc : document)#as_Document) ~name
  method eventIsEnabled ~doc ~name = IDOMImplementation.eventIsEnabled ~this:obj ~doc:((doc : document)#as_Document) ~name
--- gmetadom-0.2.3.orig/src/gdome_caml/ocaml/gdome.mli	2005-07-07 17:54:24.000000000 +0800
+++ gmetadom-0.2.3/src/gdome_caml/ocaml/gdome.mli	2005-11-28 15:44:17.000000000 +0800
@@ -153,6 +153,17 @@
    (*  [true] if the operation was succesful, [false] otherwise.           *)
    method saveDocumentToFile : doc:document -> name:string -> ?indent:bool -> unit -> bool
 
+   (* Saves an XML [document] to disk.                                     *)
+   (* Parameters:                                                          *)
+   (*  doc: The XML [document] to be saved.                                *)
+   (*  name: The name of the destination file.                             *)
+   (*  encoding: The name of the encoding.                                 *) 
+   (*  indent: if true, the document is pretty-printed indenting lines.    *)
+   (*   The default is to not indent the document.                         *)
+   (* Result:                                                              *)
+   (*  [true] if the operation was succesful, [false] otherwise.           *)
+   method saveDocumentToFileEnc : doc:document -> name:string -> encoding:string -> ?indent:bool -> unit -> bool
+
    (* Saves an XML [document] to a string.                                 *)
    (* Parameters:                                                          *)
    (*  doc: The XML [document] to be saved.                                *)
@@ -164,6 +175,18 @@
    (*  DOMImplException: if an error occurs during parsing.                *)
    method saveDocumentToMemory : doc:document -> ?indent:bool -> unit -> string
 
+   (* Saves an XML [document] to a string.                                 *)
+   (* Parameters:                                                          *)
+   (*  doc: The XML [document] to be saved.                                *)
+   (*  encoding: The name of the encoding.                                 *) 
+   (*  indent: if true, the document is pretty-printed indenting lines.    *)
+   (*   The default is to not indent the document.                         *)
+   (* Result:                                                              *)
+   (*  A new [string] containing the document.                             *)
+   (* Exceptions Raised:                                                   *)
+   (*  DOMImplException: if an error occurs during parsing.                *)
+   method saveDocumentToMemoryEnc : doc:document -> encoding:string -> ?indent:bool -> unit -> string
+
    (* Enables a DOM Event.                                                 *)
    (* Parameters:                                                          *)
    (*  doc: The XML [document]                                             *)

Reply via email to