PHP格式的xml输出

时间:2011-08-15 16:48:46

标签: php xml

此php脚本不会输出我希望指定

的格式化XML
$dom->formatOutput = true; 
$dom->preserveWhiteSpace = false;

PHP脚本

<?php

$dom = new DOMDocument();
$dom->load('communities.xml');

$dom->formatOutput = true; 
$dom->preserveWhiteSpace = false;

// get document element  

$root   = $dom->documentElement;  

$name     = $dom->createElement("NAME");  
$nameText = $dom->createTextNode("Hobbies");  
$name->appendChild($nameText); 

$community = $dom->createElement('COMMUNITY');

$community->appendChild($name);  
$root->appendChild($community); 

$dom->save('communities.xml');

$tidy_options = array(
                'input-xml'    => true,
                'output-xml'   => true,
                'indent'       => true,
                'wrap'         => false,
        );
$tidy = new tidy();
$tidy->parseFile('communities.xml', $tidy_options);
$tidy->cleanRepair();
echo $tidy;

?>

是否需要其他任何东西才能获得格式化的输出,每个标记都缩进并在一行上?

0 个答案:

没有答案