Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[dm-serializer] Don't emit XML prologue when using libxml or nokogiri…

…. There's probably a much nicer way of doing this but I couldn't find it :(

[#751 state:resolved]
  • Loading branch information...
commit e1cb5a2b8128ddc0b1fb01fcf223a9f8c020bd93 1 parent b3beaf6
@xaviershay xaviershay authored
View
6 dm-serializer/History.txt
@@ -1,3 +1,9 @@
+=== 0.9.10 / Unreleased
+
+* 1 bug fix:
+
+ * libxml and nokogiri no longer output an xml prologue
+
=== 0.9.9 / 2009-01-04
* 1 major enhancement:
View
2  dm-serializer/lib/dm-serializer/to_xml.rb
@@ -36,7 +36,7 @@ def to_xml_document(opts={}, doc = nil)
xml.add_node(root, xml_name, value.to_s) unless value.nil?
end
end
- doc
+ xml.output(doc)
end
end
View
4 dm-serializer/lib/dm-serializer/xml_serializers/libxml.rb
@@ -23,6 +23,10 @@ def self.add_node(parent, name, value, attrs = {})
end
parent << node
end
+
+ def self.output(doc)
+ doc.to_s.sub(/.*\s+/, '')
+ end
end
end
end
View
4 dm-serializer/lib/dm-serializer/xml_serializers/nokogiri.rb
@@ -22,6 +22,10 @@ def self.add_node(parent, name, value, attrs = {})
parent << node
node
end
+
+ def self.output(doc)
+ doc.to_s.sub(/.*\s+/, '')
+ end
end
end
end
View
5 dm-serializer/lib/dm-serializer/xml_serializers/rexml.rb
@@ -16,8 +16,11 @@ def self.add_node(parent, name, value, attrs = {})
node << ::REXML::Text.new(value.to_s) unless value.nil?
node
end
- end
+ def self.output(doc)
+ doc.to_s
+ end
+ end
end
end
end
View
6 dm-serializer/spec/public/to_xml_spec.rb
@@ -59,6 +59,12 @@ def cast(value, type)
it_should_behave_like "A serialization method"
+ it "should not include the XML prologue, so that the result can be embedded in other XML documents" do
+ planet = Planet.new
+ xml = planet.to_xml(:element_name => "aplanet")
+ xml.starts_with?("<?xml").should == false
+ end
+
describe ':element_name option for Resource' do
it 'should be used as the root node name by #to_xml' do
planet = Planet.new
Please sign in to comment.
Something went wrong with that request. Please try again.