title: PHP - Dynamically append web page to sitemap.xml
body: <p>I have a site that searches through a database of websites. I am trying to get to append an url to sitemap.xml whenever the search returns a single result. I know I would need to use simplexml but I'm not sure how to implement it.</p>
  
  <p><strong>Pseudo Code</strong></p>
  
  <pre><code>if (correct results) {
      $theDate = date('c',time());
      $theUrl = "http://myurl.com/?r=asdfasdf1234"
      appendtositemap($theDate, $theUrl);
  }
  </code></pre>
  
  <p><strong>Current sitemap.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"&gt;
      &lt;url&gt;
          &lt;loc&gt;http://example.com/&lt;/loc&gt;
          &lt;lastmod&gt;2013-04-08T20:38:15+00:00&lt;/lastmod&gt;
          &lt;changefreq&gt;daily&lt;/changefreq&gt;
          &lt;priority&gt;1.0&lt;/priority&gt;
      &lt;/url&gt;
  &lt;/urlset&gt;
  </code></pre>