Note that there are some explanatory texts on larger screens.

plurals
  1. POXML file creation using PHP
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/10859050/xml-formatting-is-not-working-well">XML formatting is not working well</a> </p> </blockquote> <p>I am trying to create an XML file from the database. Database contains name, phone no and sex. I would like to get all the users' details in a well-formatted XML file. But I am getting now:</p> <pre><code>&lt;CUSTOMERS&gt; &lt;name&gt;AAA&lt;/name&gt; &lt;name&gt;BBB&lt;/name&gt; &lt;/CUSTOMERS&gt; </code></pre> <p>This is my code:</p> <pre><code>$xmlstr = "&lt;?xml version='1.0' ?&gt;\n"."&lt;CUSTOMERS&gt;&lt;/CUSTOMERS&gt;"; $xml = new SimpleXMLElement($xmlstr); while($b=$result-&gt;fetch_assoc()){ $xml-&gt;addChild("name", $b['name']); } return $xml-&gt;asXML(); </code></pre> <p>I would like to get the out put as shows below</p> <pre><code>&lt;CUSTOMERS&gt; &lt;AAAA&gt; &lt;name&gt;AAA&lt;/name&gt; &lt;phone&gt;111&lt;/phone&gt; &lt;sex&gt;male&lt;/sex&gt; &lt;/AAA&gt; &lt;BBBB&gt; &lt;name&gt;BBB&lt;/name&gt; &lt;phone&gt;222&lt;/phone&gt; &lt;sex&gt;female&lt;/sex&gt; &lt;/AAA&gt; &lt;/CUSTOMERS&gt; </code></pre> <hr> <p>Latest Code</p> <pre><code> $xmlstr = "&lt;?xml version='1.0' ?&gt;\n"."&lt;CUSTOMERS&gt;&lt;/CUSTOMERS&gt;"; $xml = new SimpleXMLElement($xmlstr); while($b=$result-&gt;fetch_assoc()){ $customer = $xml-&gt;addChild("customer"); $customer-&gt;addChild("name", $b['name']); $customer-&gt;addChild("phone", $b['phone']); $customer-&gt;addChild("sex", $b['sex']); //$xml-&gt;addChild("place", $b['place']); } return $xml-&gt;asXML(); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload