Sha256: 8cd3e9aa0cf9f9d196ac9a0522abcdd38c4461f32ce1f7d20941b35c6398ce49
Contents?: true
Size: 1.87 KB
Versions: 4
Compression:
Stored size: 1.87 KB
Contents
require 'rexml/document' module ROXML module XML # :nodoc:all Document = REXML::Document Node = REXML::Element module Error def self.reset_handler # noop end end [REXML::ParseException, REXML::UndefinedNamespaceException, REXML::Validation::ValidationException].each do |exception| exception.send(:include, Error) end class Node class << self def new_cdata(content) REXML::CData.new(content) end end alias_attribute :content, :text def search(xpath) begin REXML::XPath.match(self, xpath) rescue Exception => ex raise ex, xpath end 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(source) REXML::Document.new(source, :ignore_whitespace_nodes => :all) end def parse_file(path) #:nodoc: path = path.sub('file:', '') if path.starts_with?('file:') parse(open(path)) end def parse_io(path) #:nodoc: parse(path) 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 def save(destination, opts = {:formatter => REXML::Formatters::Default.new}) self << REXML::XMLDecl.new unless xml_decl != REXML::XMLDecl.default # always output xml declaration File.open(destination, "w") do |f| opts[:formatter].write(self, f) end end end end end
Version data entries
4 entries across 4 versions & 2 rubygems
Version | Path |
---|---|
Empact-roxml-2.5.1 | lib/roxml/xml/parsers/rexml.rb |
Empact-roxml-2.5.2 | lib/roxml/xml/parsers/rexml.rb |
roxml-2.5.1 | lib/roxml/xml/parsers/rexml.rb |
roxml-2.5.2 | lib/roxml/xml/parsers/rexml.rb |