Skip Headers

Oracle9i XML Database Developer's Guide - Oracle XML DB
Release 2 (9.2)

Part Number A96620-02
Go to Documentation Home
Go to Book List
Book List
Go to Table of Contents
Go to Index
Go to Master Index
Master Index
Go to Feedback page

Go to previous page Go to next page
View PDF

Oracle XML DB Foldering

This chapter describes how to access data in Oracle XML DB Repository using standard protocols such as FTP, HTTP/WebDAV and other Oracle XML DB Resource APIs. It also introduces you to using RESOURCE_VIEW and PATH_VIEW as the SQL mechanism for accessing and manipulating Repository data. It includes a table for comparing Repository operations through the various Resource APIs.

This chapter contains the following sections:

Introducing Oracle XML DB Foldering

Using the foldering feature in Oracle XML DB you can store content in the database in hierarchical structures, as opposed to traditional relational database structures.

Figure 13-1 is an example of a hierarchical structure that shows a typical tree of folders and files in Oracle XML DB Repository. The top of the tree shows '/', the root folder.

Foldering allows applications to access hierarchically indexed content in the database using the FTP, HTTP, and WebDAV protocol standards as if the database content is stored in a file system.

This chapter provides an overview of how to access data in Oracle XML DB Repository folders using the standard protocols. There are other APIs available in this release, which allow you to access the Repository object hierarchy using Java, SQL, and PL/SQL.

Figure 13-1 A Typical Folder Tree Showing Hierarchical Structures in Oracle XML Repository

Text description of adxdb004.gif follows
Text description of the illustration adxdb004.gif


The directory /sys is used by Oracle XML DB to maintain system-defined XML schemas, ACLs, and so on. In general:

  • Do not store any data under the /sys directory.
  • Do not modify any content in the /sys directory.

See Also:

Oracle XML DB Repository

Oracle XML DB Repository (Repository) is the set of database objects, across all XML and database schemas, that are mapped to path names. It is a connected, directed, acyclic graph of resources with a single root node (/). Each resource in the graph has one or more associated path names.

The Repository can be thought of as a file system of objects rather than files.


The Repository supports multiple links to a given resource.

Repository Terminology

The following lists describes terms used in Oracle XML DB Repository:

Many terms used by Oracle XML DB have common synonyms used in other contexts, as shown in Table 13-1.

Table 13-1 Synonyms for Oracle XML DB Foldering Terms    
Synonym Oracle XML DB Foldering Term Usage






Operating systems







WebDAV Folder


Web Folder



Access control




File system


Operating systems






Operating systems




Oracle XML DB Resources

Oracle XML DB resources conform to the xdbresource.xsl schema, which is defined by Oracle XML DB. The elements in a resource include those needed to persistently store WebDAV-defined properties, such as creation date, modification date, WebDAV locks, owner, ACL, language, and character set.

Contents Element in Resource Index

A resource index has a special element called Contents which contains the contents of the resource.

any Element

The XML schema for a resource also defines an any element, with maxoccurs unbounded, which allowed to contain any element outside the Oracle XML DB XML namespace. This way, arbitrary instance-defined properties can be associated with the resource.

Where Exactly Is Repository Data Stored?

Oracle XML DB stores Repository data in a set of tables and indexes in the Oracle XML DB database schema. These tables are accessible. If you register an XML schema and request the tables be generated by Oracle XML DB, the tables are created in your database schema. This means that you are able to see or modify them. However, other users will not be able to see your tables unless you explicitly grant them permission to do so.

Generated Table Names

The names of the generated tables are assigned by Oracle XML DB and can be obtained by finding the xdb:defaultTable=XXX attribute in your XML schema document (or the default XML schema document). When you register an XML schema, you can also provide your own table name, and override the default created by Oracle XML DB.

See Also:

"Guidelines for Using Registered XML Schemas" in Chapter 5, "Structured Mapping of XMLType"

Defining Structured Storage for Resources

Applications that need to define structured storage for resources can do so by either:

Pathname Resolution

The data relating a folder to its children is managed by the Oracle XML DB hierarchical index. This provides a fast mechanism for evaluating path names, similar to the directory mechanisms used by operating-system file systems.

Resources that are folders have the Container attribute set to TRUE.

To resolve a resource name in a folder, the current user must have the following privileges:

If the user does not have these privileges, he receives an access denied error. Folder listings and other queries will not return a row when the read-properties privilege is denied on its resource.


Error handling in path name resolution differentiates between invalid resource names and resources that are not folders for compatibility with file systems. Since Oracle XML DB resources are accessible from outside the Repository (using SQL), denying read access on a folder that contains a resource will not prevent read access to that resource.

Deleting Resources

Deletion of a link deletes the resource pointed to by the link if and only if that was the last link to the resource and the resource is not versioned. Links in Oracle XML DB Repository are analogous to Unix "hard links".

See Also:

"Deleting Repository Resources: Examples"

Accessing Oracle XML DB Repository Resources

Oracle XML DB provides two techniques for accessing resources:

Figure 13-2 illustrates Oracle XML DB data access options. A high level discussion of which data access option to select is described in Chapter 2, "Getting Started with Oracle XML DB", "Oracle XML DB Application Design: b. Access Models".

See Also:

Table 13-3, "Accessing Oracle XML DB Repository: API Options"

Figure 13-2 Oracle XML DB Repository Data Access Options

Text description of adxdb027.gif follows
Text description of the illustration adxdb027.gif

A Uniform Resource Locator (URL) is used to access an Oracle XML DB resource. A URL includes the hostname, protocol information, path name, and resource name of the object.

Navigational or Path Access

Oracle XML DB folders support the same protocol standards used by many operating systems. This allows an Oracle XML DB folder to function just like a native folder or directory in supported operating-system environments. For example: you can:

Figure 13-3 Oracle XML DB Folders in Windows Explorer

Text description of 4_xfoldr.jpg follows.

Text description of the illustration 4_xfoldr.jpg

Figure 13-4 Accessing Repository Data Using HTTP/WebDAV and Navigational Access From IE Browser: Viewing Web Folders

Text description of 3_f_http.gif follows
Text description of the illustration 3_f_http.gif

Accessing Oracle XML DB Resources Using Internet Protocols

Oracle Net Services provides one way of accessing database resources. Oracle XML DB support for Internet protocols provides another way of accessing database resources.

Where You Can Use Oracle XML DB Protocol Access

Oracle Net Services is optimized for record-oriented data. Internet protocols are designed for stream-oriented data, such as binary files or XML text documents.

Oracle XML DB protocol access is a valuable alternative to Net Services in the following scenarios:

Protocol Access Calling Sequence

Protocol access uses the following steps in Oracle XML DB:

  1. A connection object is established, and the protocol may decide to read part of the request.
  2. The protocol decides if the user is already authenticated and wants to reuse an existing session or if the connection must be reauthenticated (generally the case).
  3. An existing session is pulled from the session pool, or a new one is created.
  4. If authentication has not been provided and the request is HTTP Get or Head, the session is run as the ANONYMOUS user. If the session has already been authenticated as the ANONYMOUS user, there is no cost to reuse the existing session. If authentication has been provided, the database reauthentication routines are used to authenticate the connection.
  5. The request is parsed.
  6. If the requested path name maps to a servlet (for HTTP only), the servlet is invoked using the Java VM. The servlet code writes out the response to a response stream or asks XMLType instances to do so.

Retrieving Oracle XML DB Resources

When the protocol indicates that a resource is to be retrieved, the path name to the resource is resolved. Resources being fetched are always streamed out as XML, with the exception of resources containing the XDBBinary element, an element defined to be the XML binary data type, which have their contents streamed out in RAW form.

Storing Oracle XML DB Resources

When the protocol indicates that a resource must be stored, Oracle XML DB checks the document's file name extension for .xml, .xsl, .xsd, and so on. If the document is XML, a pre-parse step is done, where enough of the resource is read to determine the XML schemaLocation and namespace of the root element in the document. This location is used to look for a registered schema with that schemaLocation URL. If a registered schema is located with a definition for the root element of the current document, the default table specified for that element is used to store that resource's contents.

Using Internet Protocols and XMLType: XMLType Direct Stream Write

Oracle XML DB supports Internet protocols at the XMLType level by using the writeToStream() Java method on XMLType. This method is natively implemented and writes XMLType data directly to the protocol request stream. This avoids the overhead of converting database data through Java datatypes, creating Java objects, and Java VM execution costs, resulting in significantly higher performance. This is especially the case if the Java code deals with XML element trees only close to the root, without traversing too many of the leaf elements, hence minimizing the number of Java objects created.

See Also:

Chapter 19, "Using FTP, HTTP, and WebDAV Protocols"

Query-Based Access

Oracle XML DB provides two Repository views to enable SQL access to Repository data:

Table 13-2 summarizes the differences between PATH_VIEW and RESOURCE_VIEW.

Table 13-2 Differences Between PATH_VIEW and RESOURCE_VIEW

Contains link properties

No link properties

Contains resource properties and path name

Contains resource properties and path name

Has one row for each unique path in the Repository

Has one row for each resource in the Repository


Each resource can have multiple paths.

The single path in the RESOURCE_VIEW is arbitrarily chosen from among the many possible paths that refer to a resource. Oracle XML DB provides operators like UNDER_PATH that enable applications to search for resources contained (recursively) within a particular folder, get the resource depth, and so on. Each row in the views is of XMLType.

DML on the Oracle XML DB Repository views can be used to insert, rename, delete, and update resource properties and contents. Programmatic APIs must be used for other operations, such as creating links to existing resources.

See Also:

Accessing Repository Data Using Servlets

Oracle XML DB implements the Java servlet API, version 2.2, with the following exceptions:

Accessing Data Stored in Oracle XML DB Repository Resources

The three main ways you can access data stored in Oracle XML DB Repository resources are through:

Table 13-3 lists common Oracle XML DB Repository operations and describes how these operations can be accomplished using each of the three methods. The table shows functionality common to three methods. Note that not all the methods are equally suited to a particular set of tasks.

See Also:
Table 13-3 Accessing Oracle XML DB Repository: API Options  
Data Access Operation Query-Based Access: RESOURCE_VIEW API Path-Based Access: Resource API for PL/SQL Path-Based Access: Protocols

Creating a resource

INSERT INTO PATH_VIEW VALUES (path, res, linkprop)

See also DBMS_XDB.CreateResource.



Updating contents of a resource using path name

UPDATE RESOURCE_VIEW SET resource = updateXML(res, '/Resource/Contents', lob) WHERE EQUALS_PATH(res, :path) > 0



Updating properties of a resource by path name

UPDATE RESOURCE_VIEW SET resource = updateXML(res, '/Resource/propname', newval, '/Resource/propname2', newval2, ...) WHERE EQUALS_PATH(res, :path) > 0



Updating the ACL of a resource

UPDATE RESOURCE_VIEW SET resource = updateXML(res, '/ Resource/ACL', XMLType) WHERE EQUALS_PATH(res, :path) > 0


Unlinking a resource, deleting it if it is the last link



Forcibly removing all links to a resource

DELETE FROM PATH_VIEW WHERE extractValue(res,'display_name') = 'My resource';


FTP: quote rm_rf<resource>

Moving a resource or folder

UPDATE PATH_VIEW SET path = newpath WHERE EQUALS_PATH(res, :path) > 0



Copying a resource or folder

INSERT INTO PATH_VIEW SELECT::newpath, resource, link FROM PATH_VIEW WHERE EQUALS_PATH(res,:oldpath)> 0

WebDav COPY;


Creating a link to an existing resource

Call dbms_xdb.Link(srcpath IN VARCHAR2, linkfolder IN VARCHAR2, linkname IN VARCHAR2);


Getting binary/text representation of resource contents by path name




Getting XMLType representation of resource contents by path name

SELECT extract(res, '/Resource/Contents/*') FROM RESOURCE_VIEW p WHERE EQUALS_PATH(Res, :path) > 0


Getting resource properties by path name

SELECT extractValue(res, '/Resource/XXX') FROM RESOURCE_VIEW WHERE EQUALS_PATH(res,:path) > 0

WebDAVPROPFIND (depth = 0);


Listing a directory


WebDAV PROPFIND (depth = 1); FTP LS

Creating a folder

ICall dbms_xdb.createFolder(VARCHAR2)


Unlinking a folder



Forcibly deleting a folder and all links to it

Call dbms_xdb.deleteFolder(VARCHAR2)


FTP: quote rm_rf <folder>

Getting a resource with a row lock



Putting a WebDAV lock on the resource

DBMS_XDB.lock(lock_type INTEGER);



Removing a WebDAV lock

DBMS_XDB.unlock(path VARCHAR2);



Committing changes


Automatically commits at the end of each request

Rollback changes



Managing and Controlling Access to Resources

You can set access control privileges on Oracle XML DB folders and resources.

See Also:

Extending Resource Metadata Properties

Oracle XML DB resources are described by XML schema, XDBResource.xsd. This XML schema is described in Appendix G, "Example Setup scripts. Oracle XML DB - Supplied XML Schemas". XDBResource.xsd declares a fixed set of metadata properties such as the Owner, CreationDate, and so on. You can specify values for these metadata attributes while creating or updating resources.

You have two options for storing proprietary (custom) tags as extra metadata with resources, that is metadata properties that are not defined by the Resource XML schema:

Frequently Asked Questions (FAQs): XML DB Repository

Why Does XML Repository Hierarchical Index Not Work?

In XML DB Release 2 (9.2) the following query worked using the hierarchical index:


But this does not work with the latest release. I get the error column not indexed. How should I use the hierarchical index to search the contents of documents in the XML Repository? In one place the documentation describes a hierarchical index that indexes path names but does not mention what type of index this is and when mentioning the DBMS_XDBT package, it describes a ConText index on the Oracle XML DB Repository hierarchy that sounds similar?

Answer: It appears that you have not created the Context index on the Repository. Note that Contains() needs the Context index for its evaluation. You can create the Context index on xdb$resource by:

  1. Using DBMS_XDBT (dbmsxdbt.sql in rdbms/admin) package or
  2. Create a Context index explicitly as follows:
    CREATE INDEX xdb.ctxi ON xdb.xdb$resource x (value(x)) 
       indextype is ctxsys.context; 

(a) is the preferred solution because it takes into account the binary contents in the Repository and filters it appropriately. Solution (b) will only index the XML and text content in the Repository.

There are two different indexes on the xdb$resource table: