日期:2014-05-17  浏览次数:20679 次

PHP生成XML怎么换行?
foreach ($data as $k) {
$add = $dom->createElement('add');
$add=$root->appendChild($add); 
$name = $dom->createAttribute("name"); 
$name=$add->appendChild($name);
$nameValue = $dom->createTextNode($k[0]);
$name->appendChild($nameValue);

$drivers=$dom->createAttribute("providerName");
$drivers=$add->appendChild($drivers);
$driversvalue=$dom->createTextNode($k[1]);
$drivers->appendChild($driversvalue);

$connectionstring="Data Source=".$k[2].";Initial Catalog=".$k[3].";Persist Security Info=True;User ID=".$k[4].";Password=".$k[5].";MAX Pool Size=2000;Min Pool Size=3;Connection Lifetime=30;Pooling=true;charset=utf8;";
$connstring=$dom->createAttribute("connectionString");
$connstring=$add->appendChild($connstring);
$connstringvalue=$dom->createTextNode($connectionstring);
$connstring->appendChild($connstringvalue);
}
$output = $dom->saveXML();
echo "<xmp>".$output."</xmp>";
}
PHP生成的XML在页面上显示不换行,怎么让它换行呢?

页面显示结果如下:
<?xml version="1.0"?> 
<connectionStrings><add name="AuthContext" providerName="MySql.Data.MySqlClient" connectionString="Data Source=....后面省略.../></connectionStrings>


------解决方案--------------------
$dom->formatOutput = true;试试
------解决方案--------------------
你说加了,在你的代码中并没有看到。