Sha256: c1ee47454fe9d7b3309fcbb8712e6725f70c10b2c0714f7631f4add84a7521f5

Contents?: true

Size: 965 Bytes

Versions: 12

Compression:

Stored size: 965 Bytes

Contents

require 'libxml'

module DataMapper
  module Serializer
    module XML
      module LibXML
        def self.new_document
          ::LibXML::XML::Document.new
        end

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

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

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

        def self.add_node(parent, name, value, attrs = {})
          value_str = value.to_s unless value.nil?
          node = ::LibXML::XML::Node.new(name, value_str)

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

          parent << node
          node
        end

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

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

Version data entries

12 entries across 12 versions & 3 rubygems

Version Path
sbf-dm-serializer-1.4.0 lib/dm-serializer/xml/libxml.rb
sbf-dm-serializer-1.3.0 lib/dm-serializer/xml/libxml.rb
sbf-dm-serializer-1.3.0.beta.2 lib/dm-serializer/xml/libxml.rb
sbf-dm-serializer-1.3.0.beta lib/dm-serializer/xml/libxml.rb
ardm-serializer-1.2.2 lib/dm-serializer/xml/libxml.rb
dm-serializer-1.2.2 lib/dm-serializer/xml/libxml.rb
dm-serializer-1.2.1 lib/dm-serializer/xml/libxml.rb
dm-serializer-1.2.0 lib/dm-serializer/xml/libxml.rb
dm-serializer-1.2.0.rc2 lib/dm-serializer/xml/libxml.rb
dm-serializer-1.2.0.rc1 lib/dm-serializer/xml/libxml.rb
dm-serializer-1.1.0 lib/dm-serializer/xml/libxml.rb
dm-serializer-1.1.0.rc3 lib/dm-serializer/xml/libxml.rb