0

I am reading in an XML file that contains in it

<description>Q&A for March</description>

This breaks the php script that I have to parse the XML file and generate an HTML page.

The command I am using to read the file is

$rssfeed = simplexml_load_file($rss_array[$i], "SimpleXMLElement", LIBXML_NOENT);

I have tried it with NULL in the second field and without either the second or third field, but nothing works.

There error returned is Warning: simplexml_load_file(): feed.xml:2251: parser error : EntityRef: expecting ';' in /volume1/web/podcasts/podfeed.php on line 19 Warning: simplexml_load_file(): Q&A for March

I do not have control over the XML output (it is a podcast feed) and the XML is parsed properly by various podcast applications, so “It’s your problem”.

This is not a duplicate, as the XML file itself does not generate any errors. As I specifically said in the question, the podcast apps process the file fine. It is PHP and only PHP that complains. The question is how to get PHP to fix the input as it gets it instead of just crashing.

lbutlr
  • 414
  • 6
  • 18
  • 1
    The XML feed is invalid - as you've discovered, XML does not allow `&` unescaped since it is itself an escape code. I'm not sure there's a way to get simpleXml to deal with this, you may need to pre-parse the text to fix these invalid entries – Rudu Aug 24 '20 at 16:10
  • https://stackoverflow.com/a/2267283/1127933 – Salines Aug 24 '20 at 16:22

0 Answers0