This php script doesn't ouput the formatted XML that I expect from specifying
$dom->formatOutput = true;
$dom->preserveWhiteSpace = false;
PHP Script
<?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->append开发者_如何学编程Child($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;
?>
Is anything else needed to get a formatted output with each tag indented and on one line?
精彩评论