Sha256: 5888fb5d8791462e2ca03a4fdadb373f43064a95ab6c0fea412d19fb199c9106

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

module ROXML
  module XML # :nodoc:all
    Document = REXML::Document
    Node = REXML::Element

    class Node
      class << self
        def new_cdata(content)
          REXML::CData.new(content)
        end

        def new_element(name)
          name = name.id2name if name.is_a? Symbol
          REXML::Element.new(name)
        end
      end

      alias_attribute :content, :text

      def search(xpath)
        REXML::XPath.match(self, xpath)
      end

      def child_add(element)
        if element.is_a?(REXML::CData)
          REXML::CData.new(element, true, self)
        else
          add_element(element)
        end
      end

      def ==(other)
        to_s == other.to_s
      end
    end

    class Parser
      class << self
        def parse(string)
          REXML::Document.new(string)
        end

        def parse_file(path)
          REXML::Document.new(open(path), :ignore_whitespace_nodes => :all)
        end

        def register_error_handler(&block)
        end
      end
      ParseError = REXML::ParseException
    end

    class Document
      delegate :search, :to => :root

      def root=(node)
        raise ArgumentError, "Root is already defined" if root
        add(node)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
Empact-roxml-2.2 lib/roxml/xml/rexml.rb