SimpleXML中处理XML后asXML('file.xml')保存的文件,没有格式排版么?一行看着是天书啊

WBOY
Release: 2016-06-23 14:26:06
Original
1327 people have browsed it

SimpleXML中构建一个xml文件,

xml->addChild()

xml->addAttribute()
神马的,

存盘时候 xml->asXML('file.xml');形成的xml文件,全在一行显示啊,

看和要疯啊,太乱拉。

他不能自动换行,缩进啥的吗?


回复讨论(解决方案)

好象是没有。。。。。 只有手动替换加上换行符了。。

加上一句:$xml->formatOutput = true;

加上一句:$xml->formatOutput = true;

我开始是用SimpleXML处理的,
$xml = simplexml_load_string($xmlstring);
addChild
addAttribute

然后为了格式这样
$xmlDoc = new DOMDocument('1.0');
$xmlDoc->formatOutput = true ;
$xmlDoc->loadXML($xml->asXML());

$xml_file_save = fopen('file\file.xml',"w");//打开文件准备写入
fwrite($xml_file_save,$xmlDoc->saveXML());
fclose($xml_file_save);//关闭文件

结果,还是一样,并没有出现换行和缩进的格式,在文件中。






好象是没有。。。。。 只有手动替换加上换行符了。。

在SimpleXml 中,怎么加呢? 能当成存字符串处理?

看手册 tidy模块

换行、缩进 对于 XML 是没有意义的,只是徒劳的增加 XML 文档的尺寸(本来就够大的了)
你用任何一款 XML 编辑器(包括浏览器)看到的都是格式化的内容

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!