Module: DataMapper::Serializer::XML::Nokogiri

Defined in:
lib/dm-serializer/xml/nokogiri.rb

Class Method Summary collapse

Class Method Details

.add_node(parent, name, value, attrs = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/dm-serializer/xml/nokogiri.rb', line 22

def self.add_node(parent, name, value, attrs = {})
  node = ::Nokogiri::XML::Node.new(name, parent.document)
  node << ::Nokogiri::XML::Text.new(value.to_s, parent.document) unless value.nil?

  attrs.each do |attr_name, attr_val|
    node[attr_name] = attr_val
  end

  parent << node
  node
end

.add_xml(parent, xml) ⇒ Object



34
35
36
# File 'lib/dm-serializer/xml/nokogiri.rb', line 34

def self.add_xml(parent, xml)
  parent << xml.root
end

.new_documentObject



7
8
9
# File 'lib/dm-serializer/xml/nokogiri.rb', line 7

def self.new_document
  ::Nokogiri::XML::Document.new
end

.output(doc) ⇒ Object



38
39
40
# File 'lib/dm-serializer/xml/nokogiri.rb', line 38

def self.output(doc)
  doc.root.to_s
end

.root_node(doc, name, attrs = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/dm-serializer/xml/nokogiri.rb', line 11

def self.root_node(doc, name, attrs = {})
  root = ::Nokogiri::XML::Node.new(name, doc)

  attrs.each do |attr_name, attr_val|
    root[attr_name] = attr_val
  end

  doc.root.nil? ? doc.root = root : doc.root << root
  root
end