PHP生成XML如何换行
时间:2021-07-01 10:21:17
帮助过:16人阅读
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 "
".$output."";
}
PHP生成的XML在页面上显示不换行,怎么让它换行呢?
页面显示结果如下:
------解决方案--------------------
$dom->formatOutput = true;试试
------解决方案--------------------
你说加了,在你的代码中并没有看到。