Model structured documents with elements, attributes, namespaces, schemas, parsing, and transformations.
Lessons
Process huge documents without exhausting memory.
Handling Large XML Files is easiest to learn by reading the example, changing it, and observing the result.
<?php
// Stream large XML without loading it all into memory
$reader = new XMLReader();
$reader->open('huge-feed.xml');
while ($reader->read()) {
if ($reader->nodeType === XMLReader::ELEMENT && $reader->name === 'item') {
$node = simplexml_load_string($reader->readOuterXML());
echo $node->title, "
";
}
}
$reader->close();Practice the Handling Large XML Files example in a small scratch file, then explain what changed and why.