title: Delete files that is not in my XML document with PHP
body: <p>I have an XML file that contains the SKU of products. I also have a folder that corresponds to this XML file.</p>
  
  <pre><code>Snippet from XML:
  &lt;Feed&gt;
    &lt;Product&gt;
      &lt;ItemCode&gt;ALT-AAB-BL&lt;/ItemCode&gt;
      &lt;BaseItemCode&gt;ALT-AAB&lt;/BaseItemCode&gt;
      &lt;StockCheckCode&gt;ALT-AAB-BL&lt;/StockCheckCode&gt;
   &lt;/Product&gt;
    &lt;Product&gt;
      &lt;ItemCode&gt;ALT-AAB-L&lt;/ItemCode&gt;
      &lt;BaseItemCode&gt;ALT-AAB&lt;/BaseItemCode&gt;
      &lt;StockCheckCode&gt;ALT-AAB-L&lt;/StockCheckCode&gt;
    &lt;/Product&gt;
    &lt;Product&gt;
      &lt;ItemCode&gt;ALT-AAB-N&lt;/ItemCode&gt;
      &lt;BaseItemCode&gt;ALT-AAB&lt;/BaseItemCode&gt;
      &lt;StockCheckCode&gt;ALT-AAB-N&lt;/StockCheckCode&gt;
   &lt;/Product&gt;
  &lt;/Feed&gt;
  </code></pre>
  
  <p>I have been trying it with php but I am a junior and dont know where to start so I will give you some pseudo code.</p>
  
  <pre><code>if $domelement-&gt;ItemCode != filename.jpg{
      delte.jpg;
  }
  </code></pre>
  
  <p>Yes this pseudo code is terrible. I basically am able to pull in the .xml file and was able to manipulate data.</p>
  
  <p>I basically want to delete the files that is not present in the xml file and preserve the rest. I know how to appedn the ItemCode with .png if I need to.</p>
  
  <pre><code>&lt;?php
  
  $dom = new DOMDocument;
  $dom-&gt;preserveWhiteSpace = false;
  $dom-&gt;formatOutput = true;
  $dom-&gt;load('altitude.xml');
  $xpath = new DOMXPath($dom);
  
  $query = sprintf('/Feed/Product/BaseItemCode');
  
  foreach($xpath-&gt;query($query) as $record) {
  //delete file that is not present in BaseItemCode
  }
  </code></pre>
  
  <p>I just want the files not present in xml->BaseItemCode (which I will append with .png or .jpg) to be deleted from the folder.</p>