简体   繁体   English

php-XML DomElement无法修饰

[英]php - XML DomElement won't prettify

Im trying to create a XML file using php. 我正在尝试使用php创建XML文件。

When I print my xml it prints it all in one line and not in proper format. 当我打印xml时,它将全部打印在一行中,而不是正确的格式。

$xml = new DomDocument();
**$xml->preserveWhiteSpace = false;
$xml->FormatOutput = true;**

$parent = $xml->createElement("foo");
$parent->setAttribute("xmlns", "http://");
$parent->setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
$parent->setAttribute("xsi:schemaLocation", "link");
$xml->appendChild($parent);
$child = $xml->createElement("foo1");
$parent->appendChild($child);
$subchile = $xml->createElement($foo);
$child->appendChild($subchile);
$s_c = $xml->createElement("foo3",$foo3);
$subchile->appendChild($s_c);

echo "<xmp>" . $xml->saveXML() . "<xml>";    
$xml->save($file_name)

it prints everything without indentations etc. 它打印所有内容而没有缩进等。

I read other questions here and followed the answers but still nothing. 我在这里阅读了其他问题,并遵循了答案,但仍然一无所获。 Can you help? 你能帮我吗?

changed $xml->FormatOutput = true; 更改$ xml-> FormatOutput = true; ---> $xml->formatOutput = true; ---> $ xml-> formatOutput = true;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM