Model structured documents with elements, attributes, namespaces, schemas, parsing, and transformations.
Lessons
Create, change, and remove nodes programmatically.
Modifying the XML DOM is easiest to learn by reading the example, changing it, and observing the result.
<?php
// SimpleXML: quick, readable access
$xml = simplexml_load_file('lessons.xml');
foreach ($xml->lesson as $lesson) {
echo $lesson->title . ' [' . $lesson['level'] . "]
";
}
// DOMDocument: full control for editing
$dom = new DOMDocument();
$dom->load('lessons.xml');
$titles = $dom->getElementsByTagName('title');
echo $titles->item(0)->nodeValue, "
";Practice the Modifying the XML DOM example in a small scratch file, then explain what changed and why.