php how to create dynamic xml sitemap
<p>i have the following code, but i want the proper sitemap standard.</p>

<p><strong>my code</strong></p>

<pre><code>$xml = new DomDocument('1.0', 'utf-8'); 
$xml-&gt;formatOutput = true; 
$products= $xml-&gt;createElement('url'); 
$product = $xml-&gt;createElement('url'); 
$xml-&gt;appendChild($products); 
$products-&gt;appendChild($product); 
$product-&gt;appendChild(new DomAttr('loc', '123')); 
$xml-&gt;save("data.xml");
</code></pre>

<p><strong>but the output of the stated code is lile:</strong></p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;url&gt;
&lt;url loc="123"/&gt;
&lt;/url&gt;
</code></pre>

<p><strong>But i want the following standard...</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://www.example.com/&lt;/loc&gt;
      &lt;lastmod&gt;2012-08-11T04:08:53+01:00&lt;/lastmod&gt;
      &lt;changefreq&gt;monthly&lt;/changefreq&gt;
      &lt;priority&gt;0.5&lt;/priority&gt;
   &lt;/url&gt;
&lt;/urlset&gt;
</code></pre>

<p>please help me in this regard.</p>
