"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"); //retrieve the appropriate filepath from the dictionary. $file = $poemdict[$poem]; //This function, which only executes if highlighting is on, gets the lines of the stanza making //the call and returns them as an array, for comparison with the stanzas being retrieved. function getLines($file,$version,$ID) { $lines = array(); //initialize array for storing lines $reader = new XMLReader(); //initialize reader $reader->open($file); //open file //move forward through the document, looking for the correct docEdition element node. while ($reader->read()) { if ($reader->nodeType == XMLReader::ELEMENT && $reader->localName == "docEdition") { $reader->read(); if ($reader->value == $version) { //start moving forward again; look for the lg element node with the correct //n attribute value. while ($reader->read()) { if ($reader->nodeType == XMLReader::ELEMENT && $reader->localName == "lg") { if ($reader->getAttribute("n") == $ID) { //then add the lines to an array. while ($reader->read()) { if ($reader->nodeType == XMLReader::ELEMENT && $reader->localName == "l") { $reader->read(); $lines[] = $reader->value; } //break loop at lg end tag. elseif ($reader->nodeType == XMLReader::END_ELEMENT && $reader->localName == "lg") { break; } } } } //break loop at text end tag (signaling end of version) elseif ($reader->nodeType == XMLReader::END_ELEMENT && $reader->localName == "text") { break; } } } } } return $lines; } //This function retrieves the stanzas in other editions corresponding to the stanza making the call. function getStanzas($file,$poem,$version,$divID,$highlight) { //call the getLines function if highlighting is set to on. if ($highlight == "true") { $lines = getLines($file,$version,$divID); } $reader = new XMLReader(); //initialize reader $reader->open($file); //open file //output a button to call the javascript hideStanzas function echo '
'; //move forward through the document, looking for the docEdition element node. For each, //if it's not the version calling the function, continue executing the function. while ($reader->read()) { if ($reader->nodeType == XMLReader::ELEMENT && $reader->localName == "docEdition") { $reader->read(); if ($reader->value != $version) { $thisversion = $reader->value; $foundmatch = "false"; //initialize $foundmatch variable to false. //start moving forward again; look for lg element node, grab its n //attribute value, and start building div boxes while ($reader->read()) { if ($reader->nodeType == XMLReader::ELEMENT && $reader->localName == "lg") { $stanzaID = $reader->getAttribute("n"); if ($stanzaID == $divID) { $foundmatch = "true"; //change $foundmatch variable to true echo '
' . $thisversion . '
'; while ($reader->read()) { if ($reader->nodeType == XMLReader::ELEMENT && $reader->localName == "head") { $reader->read(); echo "
stanza " . $reader->value . "
"; } //if highlighting is off, out the line as is. elseif ($reader->nodeType == XMLReader::ELEMENT && $reader->localName == "l" && $highlight == "false") { $reader->read(); echo $reader->value . "
"; } //if highlighting is on, compare the line to the corresponding //line in the $lines array, and if it is different, wrap the //output line in a span tag for highlighting. elseif ($reader->nodeType == XMLReader::ELEMENT && $reader->localName == "l" && $highlight == "true") { $linenumber = $reader->getAttribute("n"); $reader->read(); $thisline = $reader->value; if ($thisline == $lines[($linenumber - 1)]) { echo $thisline . "
"; } else { echo '' . $thisline . '
'; } } //break the loop at the lg end tag. elseif ($reader->nodeType == XMLReader::END_ELEMENT && $reader->localName == "lg") { echo "
"; break; } } } } //at text end tag (signaling end of version), print message if no stanza //match was found, and break loop. elseif ($reader->nodeType == XMLReader::END_ELEMENT && $reader->localName == "text") { if ($foundmatch == "false") { echo '
' . $thisversion . '
[no equivalent stanza]
'; } break; } } } } } } getStanzas($file,$poem,$version,$divID,$highlight); ?>