' . $reader->value . "
"; } elseif ($reader->nodeType == XMLReader::END_ELEMENT && $reader->localName == "lg") { echo '
"The Rubiayat of Omar Khayyam - Edward FitzGerald", "tyger"=>"The Tyger - William Blake", "leda"=>"Leda and the Swan - W.B. Yeats", "sorrow"=>"The Sorrow of Love - W.B. Yeats"); //Defines an associative array linking poem keys to appropriate file paths. $poemfiledict = array("rubiayat"=>"http://www.brianjaystanley.com/LIS/apps/rubiayat.xml", "tyger"=>"http://www.brianjaystanley.com/LIS/apps/tyger.xml", "leda"=>"http://www.brianjaystanley.com/LIS/apps/leda.xml", "sorrow"=>"http://www.brianjaystanley.com/LIS/apps/sorrow.xml"); //Defines an associative array linking poem keys to default versions. $poemversiondict = array("rubiayat"=>"4th edition", "tyger"=>"Published version", "leda"=>"Published version", "sorrow"=>"Final printed version"); //END DICTIONARIES--------------------------------------------------------------------------- //GET ARGUMENTS----------------------------------------------------------------------------- //if no poem variable is supplied (that is, on initial page load), set defaults; //otherwise use supplied parameter if (! isset($_GET["poem"])) { $poem = "rubiayat"; } else { $poem = $_GET["poem"]; } //if no version variable is supplied, set defaults; //otherwise use supplied parameter if (! isset($_GET["version"])) { $version = $poemversiondict[$poem]; //get the default version from the dictionary. } else { $version = $_GET["version"]; } $file = $poemfiledict[$poem]; //retrieve the appropriate filepath from the dictionary. //END GET ARGUMENTS-------------------------------------------------------------------------- //START FUNCTIONS----------------------------------------------------------------------------- //This function creates an array listing each version of the document except the current version. function listVersions($file,$version){ $reader = new XMLReader(); //initialize reader $reader->open($file); //open file $versions = array(); while ($reader->read()) { if ($reader->nodeType == XMLReader::ELEMENT && $reader->localName == "docEdition") { $reader->read(); if ($reader->value != $version) { $versions[] = $reader->value; } } } return $versions; } //this function displays the requested version function displayVersion($poemnamedict,$file,$poem,$version) { $reader = new XMLReader(); //initialize reader $reader->open($file); //open file //I expected the following line to convert XML entities, but it did not. Instead I //use PHP's utf8_decode function on each return value where entities might be encountered. // $reader->setParserProperty(XMLReader::SUBST_ENTITIES, TRUE); $versions = listVersions($file,$version); //move forward through the document; look for title and author element nodes, and begin //creating HTML while ($reader->read()) { if ($reader->nodeType == XMLReader::ELEMENT && $reader->localName == "title") { $reader->read(); $title = $reader->value;} if ($reader->nodeType == XMLReader::ELEMENT && $reader->localName == "author") { $reader->read(); $author = $reader->value; //output document head, navigation links, and banner. echo '