While processing XML
documents and datagrams inside the database, you’ll frequently
find it necessary and convenient to search the content of the
document you’re processing. We’ve noted that the
xmldom package provides a completely programmatic
way of hunting through the entire tree of nodes of an XML document to
find what you’re looking for. We’ll see in this section
how XPath’s searching of in-memory XML makes it all declarative
and so much easier.
We saw in Chapter 2, that XPath expressions provide a compact, declarative syntax to describe any parts of an XML document you would like to address. Let’s explore what opportunities exist for the PL/SQL developer to exploit XPath expressions to search in-memory documents.
Let’s look again at our simple insurance claim XML document:
<!-- claim77804.xml --> <Claim> <ClaimId>77804</ClaimId> <Policy>12345</Policy> <Settlements> <Payment Approver="JCOX">1000</Payment> <Payment Approver="PSMITH">1850</Payment> </Settlements> <DamageReport> The insured's <Vehicle Make="Volks">Beetle</Vehicle> broke through the guard rail and plummeted into a ravine. The cause was determined to be <Cause>faulty brakes</Cause>. Amazingly there were no casualties. </DamageReport> </Claim>
We might want to answer the following questions about this document:
We may want to store the policy number for this XML-based insurance claim in its own database ...