Module: DataMapper::Serialize::XMLSerializers::LibXML
- Defined in:
- lib/dm-serializer/xml_serializers/libxml.rb
Class Method Summary collapse
- .add_node(parent, name, value, attrs = {}) ⇒ Object
- .add_xml(parent, xml) ⇒ Object
- .new_document ⇒ Object
- .output(doc) ⇒ Object
- .root_node(doc, name, attrs = {}) ⇒ Object
Class Method Details
.add_node(parent, name, value, attrs = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/dm-serializer/xml_serializers/libxml.rb', line 18 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 |
.add_xml(parent, xml) ⇒ Object
28 29 30 |
# File 'lib/dm-serializer/xml_serializers/libxml.rb', line 28 def self.add_xml(parent, xml) parent << xml.root.copy(true) end |
.new_document ⇒ Object
5 6 7 |
# File 'lib/dm-serializer/xml_serializers/libxml.rb', line 5 def self.new_document ::LibXML::XML::Document.new end |
.output(doc) ⇒ Object
36 37 38 |
# File 'lib/dm-serializer/xml_serializers/libxml.rb', line 36 def self.output(doc) doc.root.to_s end |
.root_node(doc, name, attrs = {}) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/dm-serializer/xml_serializers/libxml.rb', line 9 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 |