Class: XMLPurifier

Inherits:
Object
  • Object
show all
Defined in:
lib/xml-purifier.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ XMLPurifier

Returns a new instance of XMLPurifier.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/xml-purifier.rb', line 11

def initialize(options={})

  # options for to: default, native, cdata, escaped
  opt = {xml: '', from: 'json', to: 'native'}.merge(options)

  @doc = Document.new(opt[:xml])

  @doc.root.each_recursive do |elem|

    if elem.text and elem.text.to_s[/^[\{\[][^\}\]]+[\}\]]$/] then

      obj = JSON.parse(elem.text)
      method('to_' + opt[:to].to_s.to_sym).call(elem, scan_obj_to_xml(obj))
    end
  end
  
end

Instance Method Details

#to_xmlObject



29
# File 'lib/xml-purifier.rb', line 29

def to_xml() @doc.to_s end