Class: Kwaff::Rexml::Parser

Inherits:
Parser
  • Object
show all
Defined in:
lib/kwaff/rexml.rb

Overview

Parse Kwaff string and return REXML::Document

ex.

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

Instance Attribute Summary

Attributes inherited from Parser

#index, #lines, #newline

Instance Method Summary collapse

Methods inherited from Parser

#initialize, #parse_cdata, #parse_comment, #parse_document, #parse_element, #parse_node_list, #parse_text, #reset, #spclen

Constructor Details

This class inherits a constructor from Kwaff::Parser

Instance Method Details

#create_comment(str) ⇒ Object



138
139
140
# File 'lib/kwaff/rexml.rb', line 138

def create_comment(str)
   return REXML::Comment.new(str)
end

#create_document(headers, root) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/kwaff/rexml.rb', line 103

def create_document(headers, root)
   Kwaff::assert() unless root.is_a?(REXML::Element)
   ## XML Declaration and Document Type
   #rexml_xmldecl  = REXML::XMLDecl.new((headers[:xmlversion] || '1.0'), headers[:encoding])
   #rexml_source   = REXML::Source.new(headers[:doctype])
   #rexml_doctype  = REXML::DocType.new(rexml_source)
   s = ''
   s << '<?xml version="' << (headers[:xmlversion] || '1.0')
   if headers[:encoding]
      s << ' encoding="' << headers[:encoding] << '"'
   end
   s << "?>\n"
   s << headers[:doctype].to_s if headers[:doctype]

   ## create XML Document
   #rexml_document = REXML::Document.new()
   #rexml_document.add(rexml_xmldecl)
   #rexml_document.add(rexml_doctype)
   rexml_document = REXML::Document.new(s)
   rexml_document.add(root)
   return rexml_document
end

#create_element(tag, children, attrs) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
# File 'lib/kwaff/rexml.rb', line 126

def create_element(tag, children, attrs)
   rexml_element = REXML::Element.new
   rexml_element.name = tag
   attrs.each do |aname, avalue|
      rexml_element.add_attribute(aname, avalue)
   end if attrs
   children.each do |child|
      rexml_element.add(child)
   end if children
   return rexml_element
end

#create_text(str, flag_escape = true) ⇒ Object



142
143
144
# File 'lib/kwaff/rexml.rb', line 142

def create_text(str, flag_escape=true)
   return flag_escape ? REXML::Text.new(str) : REXML::CData.new(str)
end

#set_node_option(node, name, value) ⇒ Object



146
147
148
# File 'lib/kwaff/rexml.rb', line 146

def set_node_option(node, name, value)
   # nothing
end