DOMDocument cannot parse XML

1.5k Views Asked by At

I'm using Zend_Feed_Atom to get a feed from a website but I'm receiving this error:

Message:

DOMDocument cannot parse XML: DOMDocument::loadXML() [domdocument.loadxml]: xmlParseEntityRef: no name in Entity, line: 827

I tried with another site and I had no error. I want to know why do I get an error with that particular page and what does this error mean. I have looked online and it says that is a problem with the encoding (Which I don't really understand).

my code is simple, its just

if($type_feed == "atom"){
    $nfeed = new Zend_Feed_Atom($address);  
}elseif($type_feed == "rss"){
    $nfeed= new Zend_Feed_RSS($address);
}

Any help would be awesome! thanks!

2

There are 2 best solutions below

2
On BEST ANSWER

If the feed is busted then it is busted, there is little we can do about that.

One method of getting around this is to use @ to suppress the error.

if($type_feed == "atom"){
    $nfeed = @new Zend_Feed_Atom($address);  
}elseif($type_feed == "rss"){
    $nfeed= @new Zend_Feed_RSS($address);
}

Note that this is not ideal as it will suppress everything when new is called.

1
On

Take a look here: http://www.php.net/manual/en/class.domdocument.php#domdocument.props.recover

Proprietary. Enables recovery mode, i.e. trying to parse non-well formed documents. This attribute is not part of the DOM specification and is specific to libxml.

You can try:

$dom = new DOMDocument();
$dom->recover = true;

Also, take a look at my implementation: https://gitlab.com/DeepRSS/Reader/blob/a2723735ff3e3cdd7d85649c92d0115211ea9a0d/src/Core/Service/ZendReader/FeedParser.php#L99