NewtFire logo: a mosaic rendering of a firebelly newt
newtFire {dh}
Creative Commons License Last modified: Sunday, 27-Feb-2022 02:06:49 UTC. Maintained by: Elisa E. Beshero-Bondar (eeb4 at psu.edu). Powered by firebellies.

Getting started

The assignment

Respond to the XPath questions below in a text or markdown file, and upload to Canvas for this assignment when you’re finished. (Please upload a file! If you paste your answers into the text box, Canvas may munch the code formatting.) I like using a separate text editor for this kind of exercise, or using the Tile Editors Vertically option in <oXygen/> (Window → Tile Editors Vertically). Some of these tasks are thought-provoking, and even difficult. If you get stuck, do the best you can, and if you can’t get a working answer, give the answers you tried and explain where they failed to get the results you wanted. Sometimes doing that will help you figure out what’s wrong, and even when it doesn’t, it will help us identify the difficult moments. Consult our introductory guide Follow the XPath! and our interactive tutorial site for help with constructing your expressions.

With The Tempest play and the XPath browser window in <oXygen/>, respond to the following questions by studying the XML files and writing XPath expressions. Be sure to give the XPath expression you used in your answer, and don’t just report your results. This way, if the answer is incorrect, we can help explain what went wrong.

  1. The Tempest, like a typical Shakespearean play, contains five acts, each of which contains scenes. Both acts and scenes are encoded as division (<div>) elements. Scroll into the document far enough so you can see the first act and the first scene to see how this is coded. Now, try writing XPath expressions to answer the following questions:
    1. How can XPath tell apart the acts and the scenes?
    2. What XPath would find just the acts?
    3. What XPath would find just the scenes?
    4. What XPath would find just the scenes inside Act II? (The Results window for the previous questions will give you a good clue: look at the numbers inside square brackets.)
  2. Stage directions (<stage> occur in a variety of places in this XML file.
    1. Write an XPath to find all the stage directions in the document wherever they may be.
    2. Write an XPath to reach into Act 3 and find all the stage directions inside that act.
    3. What XPath would find all of the stage directions that are nested inside a metrical line (<l>), that is, between the starting <l> and the ending </l>? How many stage directions are inside lines?
    4. What XPath would find all of the stage directions that are nested directly inside a speech (<sp>) and outside of the lines within a speech?
    5. Run the XPath that finds all the stage directions wherever they are in the whole play again and study the results. Look for stage directions that are not inside a speech (<sp>) or metrical line (<l>). What other element holds stage directions when they are not inside a speech or line?
    6. Now, can you write a simple XPath expression that returns all of the stage directions that are not inside a speech or a line? (Check your Results window to make sure none of them are nested inside a speech or line.) How many are there?
  3. Let's take a look at some attributes in this document. The @ symbol in XPath indicates the attribute axis.
    1. Write an XPath to find all the speeches (<sp>) and then step over to isolate their @who attributes. (The Results window shows you just the attribute values.) Record your XPath expression.
    2. Often we use attributes in XPath to filter elements, and isolate, say, only the speeches spoken by a particular character. To filter results, we use a predicate expression written inside square brackets. Look for examples of predicates in our XPath tutorial that filter elements based on their attributes. Then write an XPath expression with a predicate to return all of the speeches in the play spoken by Prospero. Record your expression and how many results you get. Try changing the speaker to Miranda: how many speeches are spoken by her?