略微加速

略速 - 互联网笔记

php xml formatOuput无效的解决办法

2017-05-18 leiting (2799阅读)

标签 PHP

设置formatOuput属性重新加载并生成一次

For anyone else who has been having issues with formatOuput not working, here is a work-around:

rather than just doing something like: 

<?php 
$outXML = $xml->saveXML(); 
?> 

force it to reload the XML from scratch, then it will format correctly: 

<?php 
$outXML = $xml->saveXML(); 
$xml = new DOMDocument(); 
$xml->preserveWhiteSpace = false; 
$xml->formatOutput = true; 
$xml->loadXML($outXML); 
$outXML = $xml->saveXML(); 
?>

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3