From: "Morris, Chris" Date: 2002-03-19T22:53:44+09:00 Subject: RE: [ANN] Xml Serialization for Ruby > > > John > Doe >
> Red Road, 6 > 98765 >
>
> > ... > >
> > If you want to get all the addresses (and only them) from a file like > this, you just have to wait for an
element while parsing the > XML source and marshal it. If you relied on the top element, you'd > have to marshal all the address book. Depending on your application, > this can be negligible as well as important. Ah, much clearer now with the example. Good point. > ["John", /^G/, 12345] > > It translated to: > > > John > ^G > 12345 > > > ...which you couldn't really express in this form: > > > > ... > > Again, another good point. Even with my typeless approach, array and hash will have to have type elements ... well, no they wouldn't -- but we need some way of delineating each element or key/value pair. Right now it's: thing thing other thing I'd like to be able to squeeze those down somehow. > Hmmm, yes, you're right. > > Yes, it does, and I get your point about not forcing it. At least we're both making good points :) It's reinforcing the need to support different approaches. > Well, let us know about that, but if you find what feels a better > approach than C#'s, then by all means go for it. :-) Ha! Well, with my subsequent post and NaHi's post about how SOAP does it, I'm convinced about the feel on a simple marshal. > Yes, that is not pretty at all, but some classes require special > handling (arrays and the likes) and some other can be optimized (true, > nil, false) so that is not too high a price to pay. Yeah, I noticed that -- there is an advantage there to the true/false/nil case. I'm not handling that now, so I'll have to check for those and change them to the class versions like xmarshal does. > I agree, that feels more OOP to me too. My application had some > requirements that prevented that: > > - I did not know in advance what classes had to be marshallable; > - even if I did, I could not create a marshaller object for each of > them because there were going to be a lot and performance would have > decreased; > - I could not use a global object either, as the stuff needed to be > thread safe, and I could not use a mutex for the same > performance reasons. Hmmm ... that's interesting. I can see with your first issue where my approach just wouldn't work -- well, could you include the module into Object? class Object include XmlSerialization end The mods to the standard types would still work, and then everything (?) gets to_xml from_xml? As for the other two options, does the included module in Object handle performance and threading issues? Because you wouldn't have all these additional marshaling objects -- they're built into each object you already have. > I added Class, Regexp and Symbol, and yes, hashes containing other > types can be marshaled. The tests pretty much cover all the types it > handles. Cool. Chris