
dm-serializer generates invalid xml
Reported by Postmodern | May 29th, 2008 @ 07:12 AM
Since to_xml uses DataMapper::Inflector.underscore, which replaces /::/ with '/', to convert class names to xml element names the resulting XML string cannot be parsed by REXML. XML element names should probably never contain '/'.
require 'data_mapper'
require 'dm-serializer'
module Ronin
class Platform
include DataMapper::Resource
property :os, String
property :version, String
end
end
>> xml = Ronin::Platform.new(:os => 'Linux', :version => '2.4.24').to_xml
=> "<ronin/platform id=''><os>Linux</os><version>2.4.24</version></ronin/platform>"
>> REXML::Document.new(xml)
REXML::ParseException: #<REXML::ParseException:
malformed XML: missing tag start
Line:
Position:
Last 80 unconsumed characters:
>> xml.gsub!(/ronin\/platform/,'ronin-platform')
>> REXML::Document.new(xml).root
=> <ronin-platform id=''> ... </>
It should also be noted that to_xml does not add the standard XML declaration to the output.
<?xml version="1.0"?>
Comments and changes to this ticket
-
Jan Kubr June 20th, 2008 @ 04:57 AM
I quickly rewrote the to_xml method to generate XML with declarations, indenting and wrapping tags for collections.
Code:
Spec:
The used xml_element_name is problematic not only for classes wrapped in a module, but also as an instance method it makes its usage in the Collection#to_xml method ugly (@model.new.send(:xml_element_name)
I can create a patch from this if you find it useful (and tell me what needs to be improved).
-
Dan Kubb (dkubb) June 20th, 2008 @ 08:28 AM
Doesn't the current to_xml output stuff like type="integer" or other type attributes to match the ActiveRecord and ActiveResource conventions?
-
Jan Kubr June 20th, 2008 @ 08:42 AM
What is does is it adds keys of the resource as attributes of the tag, so for user with key "id" it generates this opening tag:
I'm not sure why though. And it is different form what ARs do, isn't it.
-
-
Jonathan Stott (namelessjon) November 30th, 2008 @ 07:32 AM
- Tag set to bug, dm-more, dm-serializer, to_xml
- Milestone cleared.
- State changed from new to open
- Assigned user cleared.
-
Dan Kubb (dkubb) November 30th, 2008 @ 06:44 PM
- Assigned user set to Xavier Shay
Xavier, do you know if this ticket is still valid?
-
-
Xavier Shay December 1st, 2008 @ 03:11 PM
- State changed from open to resolved
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »