O'Reilly logo

Building Oracle XML Applications by Steve Muench

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Searching XML Documents with XPath

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.

Basic Use of XPath in PL/SQL

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:

What is the value of the policy number for this claim?

We may want to store the policy number for this XML-based insurance claim in its own database ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required