Formatting output to a file using PHP DOMDocument

So, I wrote this script that searches for specific nodes in the XML file, deletes it and puts a new node in it ... however, the new node is displayed like this:

<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 tried using the format $ xml-> Output = true; but it did nothing. I load the dom object from the XML file and save it back to the same file upon completion.

+3
source share
1 answer

If you want to use

$xml->formatOutput = TRUE;

you also need to install

$xml->preserveWhiteSpace = FALSE; 

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

See the difference in the code.

+11
source

Source: https://habr.com/ru/post/1778373/


All Articles