How can I parse encoded and serialized XML with REXML?

I've getting data like this:

<![CDATA[a:1:{i:0;s:6:&quot;Sometext&quot;;}]]>

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.

Thanks, Andy

Any ideas out there?

Does anyone know how to parse this kind of data in Ruby or REXML?

If you know that, you presumably know how it's being encoded to start with. I don't recognize that format at all, so you might want to provide a little more info, like WTF is it? Or e.g. what PHP function turns XML into the above, or extracts XML from it?

I've getting data like this:

<![CDATA[a:1:{i:0;s:6:&quot;Sometext&quot;;}]]>

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 GitHub - jqr/php-serialize: Use PHP's serialization methods from Ruby. ) that already does this, if not you will just have to implement the unserializing yourself.

Fred

Not really a solution, but this has to be a classic example of PHP- programmer-bass-ackwardness. They're already writing to an extensible serialization format (XML) but then just whack language-specific serialized data in instead. That's right up there with the HTTP-over- SOAP-over-HTTP stuff I've seen floating around...

--Matt Jones