I can not print correctly mysql to xml <p>I do not know where I went wrong. I want to this.</p> <pre><code> &lt;mekan&gt; &lt;Soguk Icecekler&gt; &lt;yemek&gt; &lt;urunismi&gt;Kola&lt;/urunismi&gt; &lt;fiyat&gt;2&lt;/fiyat&gt; &lt;efiyat&gt;0&lt;/efiyat&gt; &lt;/yemek&gt; &lt;yemek&gt; &lt;urunismi&gt;Kola&lt;/urunismi&gt; &lt;fiyat&gt;2&lt;/fiyat&gt; &lt;efiyat&gt;0&lt;/efiyat&gt; &lt;/yemek&gt; &lt;/Soguk Icecekler&gt; &lt;Sicak Icecekler&gt; &lt;yemek&gt; &lt;urunismi&gt;cay&lt;/urunismi&gt; &lt;fiyat&gt;2&lt;/fiyat&gt; &lt;efiyat&gt;0&lt;/efiyat&gt; &lt;/yemek&gt; &lt;yemek&gt; &lt;urunismi&gt;kahve&lt;/urunismi&gt; &lt;fiyat&gt;2&lt;/fiyat&gt; &lt;efiyat&gt;0&lt;/efiyat&gt; &lt;/yemek&gt; &lt;/Sicak Icecekler&gt; &lt;/mekan&gt; </code></pre> <p>What is my mistake?</p> <pre><code>$xml = new SimpleXMLElement('&lt;mekan/&gt;'); while($data = mysql_fetch_array($resultID)) { $kategori=$xml-&gt;addChild('Kategori'); $kategori-&gt;addChild('kategori_adi', $data["kategoriadi"]); $kategori-&gt;addChild('urunismi', $data["urunadi"]); $kategori-&gt;addChild('fiyat', $data["fiyat"]); $kategori-&gt;addChild('efiyat', $data["eskifiyat"]); } Header('Content-type: text/xml'); echo $xml-&gt;asXML(); </code></pre> <p>XML is read, but I get mistaken result.</p>