使用PHP DOMDocument格式化输出到文件

时间:2022-10-20 19:27:20

So I wrote this script that looks for certain nodes in an XML file, deletes it, and puts a new node in it's place... however, the new node is showing up like so:

所以我编写了这个脚本,在XML文件中查找某些节点,删除它,并在其中放置一个新节点......但是,新节点如下所示:

<PrintQuestion id="17767" type="pickOne">

<Standards><Standard value="CA.MATH-6-6-20" state="CA" grade="3" subject="MATH"/></Standards><References>
        <PassageRef id="1892"/>
    </References>

I've attempted to use the $xml->formatOutput = true; but that has done nothing. I'm loading the dom object from an XML file and saving it back to the same file upon completion.

我试图使用$ xml-> formatOutput = true;但那没有做任何事。我正在从XML文件加载dom对象并在完成后将其保存回同一文件。

1 个解决方案

#1


11  

When you want to use

当你想使用时

$xml->formatOutput = TRUE;

you also have to set

你还必须设置

$xml->preserveWhiteSpace = FALSE; 

You wrote preserveWhitespace (mind the 2nd s). Properties are case-sensitive in PHP.

你写了preserveWhitespace(记住第二个s)。 PHP中的属性区分大小写。

See difference on codepad

在键盘上看到差异

#1


11  

When you want to use

当你想使用时

$xml->formatOutput = TRUE;

you also have to set

你还必须设置

$xml->preserveWhiteSpace = FALSE; 

You wrote preserveWhitespace (mind the 2nd s). Properties are case-sensitive in PHP.

你写了preserveWhitespace(记住第二个s)。 PHP中的属性区分大小写。

See difference on codepad

在键盘上看到差异