Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7869073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:12:00+00:00 2026-06-03T01:12:00+00:00

I am loading a bunch of rss feeds using DOM and sometimes one will

  • 0

I am loading a bunch of rss feeds using DOM and sometimes one will 404 instead of producing the file. The problem is that the web-server sends out an html 404 page in place of the expected xml file so using this code:

$rssDom = new DOMDocument();
$rssDom->load($url);
$channel = $rssDom->getElementsByTagName('channel');
$channel = $channel->item(0);
$items = $channel->getElementsByTagName('item');

I get this warning:

Warning: DOMDocument::load() [domdocument.load]: Entity 'nbsp' not defined

Followed by this error:

Fatal error: Call to a member function getElementsByTagName() on a non-object

Normally, this code works fine, but on the occasion that I get a 404 it fails to do anything. I tried a standard try-catch around the load statement but it doesn’t seem to catch it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T01:12:03+00:00Added an answer on June 3, 2026 at 1:12 am

    You can suppress the output of parsing errors with

    libxml_use_internal_errors(true);
    

    To check whether the returned response is a 404 you can check the $http_response_header after the call to DOMDocument::load()

    Example:

    libxml_use_internal_errors(true);
    $rssDom = new DOMDocument();
    $rssDom->load($url);
    if (strpos($http_response_header[0], '404')) {
        die('file not found. exiting.');
    }
    

    The alternative would be to use file_get_contents and then check the response header and if its not a 404 load the markup with DOMDocument::loadXml. This would prevent DOMDocument from parsing invalid XML.

    Note that all this assumes that the server correctly returns a 404 header in the response.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a UITableView that's loading a bunch of RSS feeds, and the favicon
I am loading in a bunch of data that contains dates formatted as shown
I am using NHibernate with NHibernate.Linq, and have a bunch of dynamically loading modules
I am loading a bunch of images using knockoutjs. I get a json object
I'm loading a page in Django that summarizes information from a bunch of database
I am loading a bunch of images for a GUI which will pick attributes
I am interested in loading a bunch of data TEXT files which will then
I have a page where I am loading bunch of images initially when the
I have a bunch of thumbnails which I am loading with a style of
I've seen a bunch of articles relating to loading the entire Rails environment for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.