8.7. Querying the Repository

In this section, we will describe how to query the XML repository.

8.7.1. Ad Hoc SQL Queries

Once we have uploaded some documents into the database, we can start experimenting with queries. For example, the query in Listing 8.68 will return a list of the element names that appear, with their x and y coordinates and namespace prefixes (if any).

Listing 8.68. SQL Query
SELECT n.x, n.y, e.ns_prefix, e.local_name
  FROM element_name e, node n
 WHERE n.doc_id = 1 AND n.node_id = e.node_id;

The results for wml-example.xml (document ID = 1, if we loaded this document first) are shown in Listing 8.69.

Listing 8.69. Results for wml-example.xml
 x y ns_prefix local_name ---- ---- --------- ---------- 2 49 NULL wml 5 34 NULL ...

Get XML Data Management: Native XML and XML-Enabled Database Systems now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.