We have to_yaml. How about to_xml?

Hi,

As I was sitting here contemplating my navel lint yet again, I was
thinking to myself, “self, being able to call to_yaml on objects after
require’ing the yaml package is kinda cool”. Then I thought to
myself, “Wouldn’t it also be cool if I could call to_xml on objects
after require’ing the rexml package?”.*

Yes, I’m aware of xmarshal, but wouldn’t it be cool to have that
builtin and included as part of the stdlib? I think so, and this is
coming from a guy who isn’t a big xml fan. I just thought it would be
convenient and might just make the lives easier for other folks and/or
packages, e.g. xml-rpc, soap, etc.

Just a thought.

Dan

  • You’ll note I left out ‘self’ in the second though because, hey,
    this is Ruby, and ‘self’ can be explicit or implicit. :wink:

Yes, I’m aware of xmarshal, but wouldn’t it be cool to have that
builtin and included as part of the stdlib?

agreed, but maybe you did’nt noticed that we have xml marshaller :slight_smile:

in SOAP:

require ‘soap/marshal’
=> true
class C
def initialize
@a,@b=1,‘ciao’
end
end
=> nil
SOAP::Marshal.dump(C.new)
=> “<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<env:Envelope
xmlns:xsd="http:
//www.w3.org/2001/XMLSchema"\n
xmlns:env="http://schemas.xmlsoap.org/soap/e
nvelope/"\n
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance\”>\n \n <C xmlns:n1="http://www.ruby-lang.org/xmlns/ruby/type/custom\“\n
xsi:type="n1:C"\n
env:encodingStyle="http://schemas.xmlsoap.org/s
oap/encoding/">\n <a xsi:type="xsd:int">1\n <b
xsi:type="xsd:s
tring">ciao\n \n </env:Body>\n</env:Envelope>”

and in XMLRPC:

require ‘xmlrpc/marshal’
=> true
XMLRPC::Marshal.dump(C.new)
RuntimeError: Wrong type!
from c:/Programmi/Ruby/lib/ruby/1.8/xmlrpc/create.rb:264:in
`conv2value’

    from c:/Programmi/Ruby/lib/ruby/1.8/xmlrpc/create.rb:136:in

methodRespo nse' from c:/Programmi/Ruby/lib/ruby/1.8/xmlrpc/create.rb:135:in collect’
from c:/Programmi/Ruby/lib/ruby/1.8/xmlrpc/create.rb:135:in
methodRespo nse' from c:/Programmi/Ruby/lib/ruby/1.8/xmlrpc/marshal.rb:56:in dump_respon
se’
from c:/Programmi/Ruby/lib/ruby/1.8/xmlrpc/marshal.rb:28:in
`dump’
from (irb):11

class C
include XMLRPC::Marshallable
end
=> C
XMLRPC::Marshal.dump(C.new)
=> “<?xml version=\"1.0\" ?><membe
a1b<
ciaoclass<str
C</methodRespons
\n”

on a sidenote I believe that XMLRPC::Marshal should work even with
ibject that quacks like Marshallable just like SOAP::Matshal do.

···

il 16 May 2004 15:56:19 -0700, djberg96@hotmail.com (Daniel Berger) ha scritto::

Hi,

gabriele renzi wrote:

on a sidenote I believe that XMLRPC::Marshal should work even with
ibject that quacks like Marshallable just like SOAP::Matshal do.

Agree. But I can understand this behavior.

User might not want to send the serialized object via XML-RPC payload
when it is not marked “serialize OK”. For that user, raising an
exception as current xmlrpc4r is useful. At fact, soap4r did the same
in the past.

Talking about soap4r, one day I thought about duck-type-ness of Ruby and
changed this feature, but the people from Java world(static-type world)
will tend to like the former behavior.

Regards,
// NaHi