in reply to Unmangle RSS encodings

I'd tend to say that you can do something quite simple: If your XML parser refuses to parse it, throw it out. That's how XML is supposed to work. OTOH, a quick glance at that URL in mozilla does not give a parse error, so it must not be invalid XML. (Note that it being invalid utf8 would automatically make it invalid XML.)

At this point, you have two choices, both valid, on what to do about it. You can either display it just like it says to display it: AÂÂ’s and all -- which is what the feed tells you to do -- or you can try and make it look more or less like what it's supposed to be.

If you want to do the later, try this: Your XML parser should already decode the "outer" (XML) layer of the double-encoding, and give you AÂÂ’s. Run a simple m/&\w+;/ against it. If that matches, it's probably been HTML-encoded before being XML-encoded. Run it though HTML::Entities to HTML-decode it.

Note that this will get it down to "A&ÂÂ’s", which may or may not have been what they originally intended (I suspect they meant to say A&Â's, and the extra  came from somewhere completely random). It is, however, as close as you can reasonably get.


Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).

Replies are listed 'Best First'.
Re^2: Unmangle RSS encodings
by qq (Hermit) on Jul 01, 2004 at 05:00 UTC

    I'm going to throw it out. It _is_ valid xml, and its it is _valid_ utf8 - but its still garbage. The final result is supposed to be, simply, "A's" (I checked the link the rss item points to).

    I don't think the extra  is exactly random, however, and I'm sure if I really understood unicode and encodings I could at least make a reasonable guess at what has been done to that poor string. One day...

    qq