title: if xml element exists, exit or skip
body: <p>how do i check in xml [with php dom] that if a particular element exists, it should not repeat it. for example, if i have an element 'activity', it should check against the xml file if this element exists, and if it does, it will not create it again.</p>
  
  <p>in other words, i would like to create the element 'activity' only once in the beginning, but the other elements can be recurring.</p>
  
  <p>this is the php code:</p>
  
  <pre><code>&lt;?php
      header("Location: index.php");
  
      $xmldoc = new DOMDocument();
      if(file_exists('sample.xml')){
      $xmldoc-&gt;load('sample.xml');
      } else {
      $xmldoc-&gt;loadXML('&lt;root/&gt;');
      }
      $newAct = $_POST['activity'];
      $newTime = $_POST['time'];
  
      $root = $xmldoc-&gt;firstChild;
  
      $newElement = $xmldoc-&gt;createElement('activity'); 
      $root-&gt;appendChild($newElement);
  
      $newText = $xmldoc-&gt;createTextNode($newAct);
      $newElement-&gt;appendChild($newText);
  
      $newElementE = $xmldoc-&gt;createElement('time');
      $root-&gt;appendChild($newElementE);
  
      $newTextE = $xmldoc-&gt;createTextNode($newTime);
      $newElementE-&gt;appendChild($newTextE);
  
      $xml-&gt;formatOutput = true; 
      $xmldoc-&gt;save('sample.xml');
  
  
  ?&gt;
  </code></pre>