Oracle9i XML Database Developer's Guide - Oracle XML DB Release 2 (9.2) Part Number A96620-02 |
|
|
View PDF |
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:
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.
Caution: The directory /sys is used by Oracle XML DB to maintain system-defined XML schemas, ACLs, and so on. In general: |
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 following lists describes terms used in Oracle XML DB Repository:
/
), element separators /,
and various subelements (or path elements). A path element may be composed of any character in the database character set except \
and /
, which have special meanings in Oracle XML DB. The forward slash is the default name separator in a path name, and the backward slash is used to escape characters. The Oracle XML DB configuration file xdbconfig.xml
also contains a list of user-defined characters that may not appear within a path name (<invalid-pathname-chars
>).XMLType
.XDBBinary
: An XML element defined by the Oracle XML DB schema that contains binary data. XDBBinary
elements are stored in the Repository when unstructured binary data is uploaded into Oracle XML DB.XMLType
object that is mapped into the Oracle XML DB file system hierarchy).
Many terms used by Oracle XML DB have common synonyms used in other contexts, as shown in Table 13-1.
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.
A resource index has a special element called Contents
which contains the contents of the resource.
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.
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.
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" |
Applications that need to define structured storage for resources can do so by either:
XDB$RESOURCE
.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.
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".
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".
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.
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:
Text description of the illustration 4_xfoldr.jpg
Oracle Net Services provides one way of accessing database resources. Oracle XML DB support for Internet protocols provides another way of accessing database resources.
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 uses the following steps in Oracle XML DB:
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.XMLType
instances to do so.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.
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.
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.
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
.
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:
|
Oracle XML DB implements the Java servlet API, version 2.2, with the following exceptions:
web.xml
files are not supported. Oracle XML DB supports a subset of the XML configurations in this file. An XSL stylesheet can be applied to the web.xml
to generate servlet definitions. An external tool must be used to create database roles for those defined in the web.xml
file.HTTPSession
and related classes are not supported.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.
You can set access control privileges on Oracle XML DB folders and resources.
See Also:
|
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:
any
element (declared with maxOccurs
= "unbounded
"), thus allowing any valid XML data as part of the resource document, and gets stored in the RESEXTRA
CLOB column:
Note: The XML representing user level metadata must be within a namespace other than that |
<Resource xmlns="http://xmlns.oracle.com/xdb/XDBResource.xsd" <Owner>SCOTT</Owner> ... <!-- other system defined metadata --> <!-- User Metadata (appearing within different namespace) --> <ResExtra> <myCustomAttrs xmlns="http://www.example.com/customattr"> <attr1>value1</attr1> <attr2>value2</attr2> </myCustomAttrs> </ResExtra <!-- contents of the resource> <Contents> ... </Contents> </Resource>
Though this approach works well for ad-hoc extensions to the resource metadata, the queryability and updatability of the user metadata is impacted because the user metadata is stored in a CLOB.
ResourceType
complexType
. This triggers the creation of object subtypes under the XDB$RESOURCE_T object
type, thereby adding new columns to the XDB$RESOURCE
table:
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xdbres="http://xmlns.oracle.com/xdb/XDBResource.xsd" <complexType name="myCustomResourceType> <complexContent> <extension base="xdbres:ResourceType> <element name="custom-attr1" type="string"> ... </extension> </complexContent> </complexType> </schema>
In XML DB Release 2 (9.2) the following query worked using the hierarchical index:
SELECT XDBURITYPE(ANY_PATH).GETXML() FROM RESOURCE_VIEW WHERE CONTAINS(RES,'MYXML') >0;
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:
(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: