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


In reply to Re: Unmangle RSS encodings by theorbtwo
in thread Unmangle RSS encodings by qq

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.