[ruby-oci8-devel] About XML DB support in Ruby-OCI8

KUBO Takehiro kubo at jiubao.org
Tue Apr 1 01:47:53 EDT 2008


Hi Liming,

I have found an other way to support XML.
It just add the following code at the end of lib/oci8/oci8.rb

--------------------------------------------------------
autoload(:REXML, 'rexml/document')
class OCI8
  module BindType
    class REXML < OCI8::BindType::Long
      def set(val)
        super(val && val.to_s)
      end
      def get
        (val = super) && ::REXML::Document.new(val)
      end
    end
  end
end
OCI8::BindType::Mapping[:xmltype] = OCI8::BindType::REXML
--------------------------------------------------------

We can add support for other XML libraries easily. For example:
--------------------------------------------------------
# Hpricot: http://code.whytheluckystiff.net/hpricot/
require 'rubygems'
require 'hpricot'
class OCI8
  module BindType
    class HpricotXML < OCI8::BindType::Long
      def set(val)
        super(val && val.to_s)
      end
      def get
        (val = super) && ::Hpricot.XML(val)
      end
    end
  end
end
OCI8::BindType::Mapping[:xmltype] = OCI8::BindType::HpricotXML
--------------------------------------------------------

libxml ruby <http://libxml.rubyforge.org/> binding will be made by similar way.


More information about the ruby-oci8-devel mailing list