I have created a xml from an array using php.The result is listed below.
<Mst><Mstrow><sCode>10</sCode>Test<sName></sName></Mstrow></Mst>
But I want to show this xml with white spaces between each element lik this
<Mst> <Mstrow> <sCode>10</sCode> <sName>Test</sName> </Mstrow> </Mst>
Below is my code ,
$results = Array ( [0] => Array ( [sCode] => 10 [sName] => Test) ) ;
$main = $dom->appendChild($dom->createElement('Mst'));
if($results != Array()){
foreach ($results as $datas) {
$row ->$main->appendChild($dom->createElement('Mstrow'));
foreach ($datas as $name => $value) {
$row
->appendChild($dom->createElement($name))
->appendChild($dom->createTextNode($value));
}
}
}
Please provide a solution
I may have missunderstood the qn, and I assume in your (pre) example test should be between <sName>
tags. I would have thought a simple string replace before you echo/save your XML string would do the trick?
eg
echo str_replace( '><' , '> <', $myXml->asXML());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.