Frederick Cheung
2009-Oct-13 08:33 UTC
Re: How can I parse encoded and serialized XML with REXML?
On Sep 24, 2:14 pm, Andy <andym...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''ve getting data like this: > > <![CDATA[a:1:{i:0;s:6:"Sometext";}]]> > > I know in PHP I can unserialize and decode, but I''m not sure the best > way to do it in Rails. > > I''m already parsing the XML using REXML so I''m hoping to continue to > use that. >Well the CDATA bit is just XML''s way of conveniently storing chunks of data with arbitrary contents, so REXML should handle that. What''s inside looks like a php serialized object. Unsurprisingly ruby does not come with functions to deal with serialized php objects (and I suspect php doesn''t come with libraries to parse ruby''s serialized object format). If you''re lucky there will be a gem out there (maybe http://github.com/jqr/php-serialize ) that already does this, if not you will just have to implement the unserializing yourself. Fred> Thanks, > Andy