The Document Object Model in PHP

This file is created with PHP DOM. Very pointless :-)


<?php

  header('Content-Type: text/html;charset=utf-8');
  $doc = new domDocument;
  $doc->preserveWhiteSpace = true;
  
  $doc->encoding = 'utf-8';
  $doc->load('file.xml');

  $titel = $doc->getElementsByTagName('title')->item(0);
  $titel->nodeValue = 'PHP: Document Object Model';

  $heading = $doc->getElementsByTagName('h1')->item(0);
  $heading->nodeValue = 'The Document Object Model in ';
    $abbr = $doc->createElement('abbr');
    $abbr->setAttribute('title', 'PHP: Hypertext Preprocessing');
    $abbr->nodeValue = 'PHP';
    $heading->appendChild($abbr);

  $par = $doc->getElementsByTagName('p')->item(0);
  $par->nodeValue = 'This file is created with PHP DOM.';
  
  $body = $doc->getElementsByTagName('body')->item(0);
    $par = $doc->createElement('p');
    $par->appendChild($doc->createTextNode('Also check '));
      $anc = $doc->createElement('a');
      $anc->setAttribute('href', 'file.xml');
      $anc->appendChild($doc->createTextNode('this file'));
    $par->appendChild($anc);
    $par->appendChild($doc->createTextNode('.'));
    
  $body->appendChild($par);
  
  $doc->formatOutput = true;
  
  echo $doc->saveXML();
  
?>

Also check out this file.