Example (1) - DOM

The following code reads (analyses, "parses") XML document and writes it back to file (serializes it).

$dom = new DOMDocument();

// configuration for read
$dom->preserveWhiteSpace = FALSE;
$dom->load('input.xml');

// configuration for write
$dom->formatOutput = TRUE;
$dom->encoding = 'utf-8';
$dom->save('output.xml');