Module: Kwaff::Rexml

Defined in:
lib/kwaff/rexml.rb

Overview

  • To convert XML string to Kwaff format string, use Kwaff::Rexml::revert()

  • To convert Kwaff format string to REXML::Document tree, use Kwaff::Rexml::Parser or Kwaff::Rexml::parse_document().

  • To convert Kwaff::Document tree to REXML::Document tree, use Kwaff::RexmlTranslator.

  • To convert REXML::Document tree to Kwaff format string, use Kwaff::Rexml::KwaffTranslator

  • To convert REXML::Document tree to Kwaff::Document tree, use Kwaff::Rexml::ReverseTranslator.

Defined Under Namespace

Classes: KwaffTranslator, Parser, ReverseTranslator, Translator

Class Method Summary collapse

Class Method Details

.parse_document(kwaff_str, toppings = {}) ⇒ Object

return an intance of REXML::Document

ex.

kwaff_str = File.open('file.kwaff') { |f| f.read }
rexml_document = Kwaff::parse_document(kwaff_str)


367
368
369
370
371
# File 'lib/kwaff/rexml.rb', line 367

def self.parse_document(kwaff_str, toppings={})
   parser = Kwaff::Rexml::Parser.new(kwaff_str, toppings)
   rexml_document = parser.parse_document()
   return rexml_document
end

.revert(xml_str, toppings = {}) ⇒ Object

convert XML string to Kwaff string.

ex.

xml_str = File.open('file.xml') { |f| f.read }
kwaff_str = Kwaff::Rexml::revert(xml_str)


380
381
382
383
384
385
386
387
388
389
# File 'lib/kwaff/rexml.rb', line 380

def self.revert(xml_str, toppings={})
   rexml_document = REXML::Document.new(xml_str)
   if !toppings[:newline]
      pos = xml_str.index(?\n)
      toppings[:newline] = "\r\n" if xml_str[pos-1] == ?\r
   end
   translator = Kwaff::Rexml::KwaffTranslator.new(toppings)
   kwaff_str = translator.translate(rexml_document)
   return kwaff_str
end