We have to_yaml. How about to_xml?

D

Daniel Berger

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. ;)
 
G

gabriele renzi

il 16 May 2004 15:56:19 -0700, (e-mail address removed) (Daniel Berger) ha
scritto::


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 :)

in SOAP:
=> "<?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 <env
:Body>\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</a>\n <b
xsi:type=\"xsd:s
tring\">ciao</b>\n </C>\n </env:Body>\n</env:Envelope>"



and in XMLRPC:
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=> "<?xml version=\"1.0\"
?><methodResponse><params><param><value><struct><membe
r><name>a</name><value><i4>1</i4></value></member><member><name>b</name><value><
string>ciao</string></value></member><member><name>___class___</name><value><str
ing>C</string></value></member></struct></value></param></params></methodRespons
e>\n"


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

NAKAMURA, Hiroshi

Hi,

gabriele said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top