Home > Backend Development > PHP Tutorial > php创建xml并格式化输出

php创建xml并格式化输出

WBOY
Release: 2016-06-23 13:33:10
Original
1211 people have browsed it

DOMDocument创建xml,设$dom->formatOutput = true;但创建出来的只有根节点下的第一级节点才被格式化,而第一级节点下的子节点并没有(图1)。我想要的是整个xml文件都格式化输出(图2)
图1:

图2:


回复讨论(解决方案)

你的代码呢,贴出来呀。

$dom = new DOMDocument('1.0', 'UTF-8');$dom->formatOutput = true;header("Content-Type: text/plain");$rootelement = $dom->createElement("data");foreach($tree[0]['children'] as $t){	$categorys=$dom->createElement("categorys","");	$text=$dom->createElement("text",$t['text']);	$categorys->appendChild($text);        foreach($t['children'] as $child){		$category=$dom->createElement("category","");		$text2=$dom->createElement("text",$child['text']);		$category->appendChild($text2);		for($i=1;$i<=4;$i++){			$comment=$dom->createElement("comment".$i,"");//评语			$category->appendChild($comment);		}		$categorys->appendChild($category);	}	$rootelement->appendChild($categorys);}$dom->appendChild($rootelement);$filename = $this->appurl.$this->modeldir."/template/".$lang."/eval_tytakg.xml";$dom->save($filename);
Copy after login

你的代码呢,贴出来呀。

已贴出

善用tidy
这个咚咚是html/xml的福音,花点时间了解一下还是值得的

已解决

DOMDocument创建xml,设$dom->formatOutput = true;但创建出来的只有根节点下的第一级节点才被格式化,而第一级节点下的子节点并没有(图1)。我想要的是整个xml文件都格式化输出(图2)
图1:

图2:



请问楼主是如何解决的,能否分享解决办法?小弟不胜感激!
Related labels:
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template