Top Level Namespace

Defined Under Namespace

Modules: OSA Classes: String

Constant Summary collapse

USE_LIBXML =

If libxml-ruby is not present, switch to REXML.

begin
  require 'xml/libxml'

  # libxml-ruby bug workaround.
  class XML::Node
    alias_method :old_cmp, :==
    def ==(x)
      (x != nil and old_cmp(x))
    end
  end
  true
rescue LoadError
  require 'rexml/document'

  # REXML -> libxml-ruby compatibility layer.
  class REXML::Element
    alias_method :old_find, :find
    def find(path=nil, &block)
      if path.nil? and block
        old_find { |*x| block.call(*x) }
      else
        list = []
        ::REXML::XPath.each(self, path) { |e| list << e }
        list
      end
    end
    def [](attr)
      attributes[attr]
    end
    def find_first(path)
      ::REXML::XPath.first(self, path)
    end
  end
  false
end