Module: Shale::Adapter::REXML
- Defined in:
- lib/shale/adapter/rexml.rb,
lib/shale/adapter/rexml/node.rb,
lib/shale/adapter/rexml/document.rb
Overview
REXML adapter
Defined Under Namespace
Class Method Summary collapse
-
.create_document(_version = nil) ⇒ Object
private
Create Shale::Adapter::REXML::Document instance.
-
.dump(doc, pretty: false, declaration: false, encoding: false) ⇒ String
private
Serialize REXML document into XML.
-
.load(xml) ⇒ Shale::Adapter::REXML::Node
private
Parse XML into REXML document.
Class Method Details
.create_document(_version = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create Shale::Adapter::REXML::Document instance
75 76 77 |
# File 'lib/shale/adapter/rexml.rb', line 75 def self.create_document(_version = nil) Document.new end |
.dump(doc, pretty: false, declaration: false, encoding: false) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Serialize REXML document into XML
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/shale/adapter/rexml.rb', line 41 def self.dump(doc, pretty: false, declaration: false, encoding: false) if declaration ver = nil enc = nil if declaration.is_a?(String) ver = declaration end if encoding == true enc = 'UTF-8' else enc = encoding || nil end doc.add(::REXML::XMLDecl.new(ver, enc)) end io = StringIO.new if pretty formatter = ::REXML::Formatters::Pretty.new formatter.compact = true else formatter = ::REXML::Formatters::Default.new end formatter.write(doc, io) io.string end |
.load(xml) ⇒ Shale::Adapter::REXML::Node
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Parse XML into REXML document
24 25 26 27 28 29 |
# File 'lib/shale/adapter/rexml.rb', line 24 def self.load(xml) doc = ::REXML::Document.new(xml, ignore_whitespace_nodes: :all) Node.new(doc.root) rescue ::REXML::ParseException => e raise ParseError, "Document is invalid: #{e.}" end |