title: Avoiding Errors When Attempting to Load an Unavailable File
body: <p>Using php I want to load XML files from several websites and want to prevent errors if my one of the sites is down. I'm using this code to access the URL.</p>
  
  <pre><code>function get_xml($url){
   $xmlDoc = new DOMDocument();
   $xmlDoc-&gt;load($url); // This is the line causing errors
   $channel=$xmlDoc-&gt;getElementsByTagName('channel')-&gt;item(0);
   ...
  </code></pre>
  
  <p>If there is no xml feed available at $url I get lots of error messages like:</p>
  
  <p>Warning: DOMDocument::load(): Space required after the Public Identifier </p>
  
  <p>Warning: DOMDocument::load(): SystemLiteral " or ' expected</p>
  
  <p>Warning: DOMDocument::load(): SYSTEM or PUBLIC, the URI is missing </p>
  
  <p>Warning: DOMDocument::load(): Opening and ending tag mismatch: link line 5 and head </p>
  
  <p>What can I do to prevent $url from attempting to load if the feed isn't available?
  I've tried:</p>
  
  <pre><code>if(file_exists($url)){
  $xmlDoc-&gt;load('$url');
  }
  </code></pre>
  
  <p>And things with fopen and @load but I could well have been using them incorrectly.</p>