Maintained by: David J. Birnbaum (djbpitt@gmail.com)
Last modified:
2023-01-08T17:47:32+0000
You can find an XML (TEI) version of Shakespeare’s Hamlet at http://dh.obdurodon.org/bad-hamlet.xml. We’ve deliberately
damaged some of the markup in this edition to introduce some inconsistencies, but the
file is well-formed XML, which means that you can use XPath to explore it. You should
download this file to your computer (typically that means right-clicking on the link and
selecting save as
) and open it in <oXygen/>.
Prepare your answers to the following questions in a markdown file upload it to Canvas as an attachment. As always, code snippets (including XPath snippets) in markdown must be surrounded with backticks.
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. As always, you are encouraged
to ask questions in the #xpath channel in Slack, but because you want to make
progress in learning to debug your own code, your questions should tell us what you
tried, what you expected, exactly what you got instead (not just didn’t
work
or got an error
), and what you think the source of the problem is.
Sometimes writing that sort of request for advice that will help you figure out what’s
wrong on your own (see Rubber duck debugging), and even when it doesn’t, it will help us identify the
difficult moments.
These tasks require the use of path expressions, predicates, and functions. References to Kay are to the Michael Kay book; there’s a link in our online course description to a PDF version accessible through the Pitt library system. There may be more than one possible answer.
Using the Bad Hamlet document and the XPath browser window in <oXygen/>, construct XPath expressions that will do the following. Give the full XPath expressions in your answers, and not just the results:
<stage>
in the entire document? (Note: there
should be only one!)@xml:id
attribute
that is associated with it?<sp>
elements with more than 8 line (<l>
)
subelements (which may be children or deeper descendants)? You’ll need to use the
count()
function (Kay 733–34).distinct-values()
function (Kay 749–50).<stage>
) in
the play. What XPath would find the last line
(<l>
) in the play? What XPath would find the
last stage direction or line (that is, whichever of the last stage
direction and last line comes last)? You’ll need to use the union
operator (Kay 628–31).@xml:id
associated with the last cast
member in the cast list. What’s the difference between an XPath that returns the
@xml:id
attribute itself and an XPath that
returns just the value of the @xml:id
attribute? That is, what are the two XPath expressions and what does each of them
return? You’ll need to use the data()
or
string()
function (Kay 741–43, 877–79).<sp>
elements) with
more than 8 line (<l>
) subelements. What
XPath expressions would select speeches with more than 8 line child elements (one
XPath expression) and speeches with more than 8 descendant line elements (the
expression you created for #3, above)? How do those results differ? If there are
descendant line elements that are not children of a speech, what XPath expression
will return the element names of their parents? You’ll need to use the
name()
function (Kay 835–37).You should turn in your answers to the above questions in a markdown file, that is, a file with the extension .md.