Model structured documents with elements, attributes, namespaces, schemas, parsing, and transformations.
Lessons
Indent and format XML for readability.
Formatting & Pretty-Printing is easiest to learn by reading the example, changing it, and observing the result.
<?php
$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true; // indent the output
$dom->loadXML('<lessons><lesson>XML</lesson></lessons>');
echo $dom->saveXML();Practice the Formatting & Pretty-Printing example in a small scratch file, then explain what changed and why.