SimplePie & ‘ampersand’ invalid XML error

I was using one of the APIs to process their XML file using SimplePie, but it happens so that their XML document was invalid since one of the fields contained the ampersand character.

How did I resolve it? SimplePie accepts “set_raw_data($feed_string)” as one of its options. This means that you don’t have to use the URL to parse the feed.

So first, download the content of the XML through file_get_contents() method in PHP, then replace the string using str_replace(‘&’, ‘&amp’, $feed) and then you are safe to go.

I’m not entirely sure what other implications this has, but it’s serving me well so far.

About Eric

ericbae.com - just a small place for me to jot down whatever I need to jot down. not much here. so don't get too disappointed. i won't.
This entry was posted in Anything & Everything. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>