alt
Advertisement
Online Training
Career Series
Exforsys
Exforsys arrow Tutorials arrow PHP Oracle arrow Using Oracle XML DB Repository
Site Search


Using Oracle XML DB Repository

Using Oracle XML DB Repository

Another variation on accessing and manipulating XML content stored in Oracle database is provided by Oracle XML DB repository, which is an essential component of Oracle XML DB.

NOTE: Oracle XML DB repository, also known as XML repository, is a hierarchically organized repository seamlessly integrated with Oracle Database, containing resources that can be manipulated using a file/ folder/URL metaphor.

The most significant thing about XML repository is that it makes it possible to access and manipulate XML data in a number of different ways, including SQL, PL/SQL, and standard internet protocols, such as HTTP, FTP, and WebDAV. Graphically, it looks as shown in the following figure.

You may find it convenient to think of Oracle XML DB repository as a file system whose metadata and data are stored in the database. Like a conventional file system, Oracle XML DB repository contains resources: files and folders. However, in the case of XML repository, each resource also can be accessed through SQL.

NOTE: Although XML repository is optimized for working with XML data, you can use it to store non-XML data as well. For example, you might store a collection of pictures there.

Manipulating Repository Resources with PL/SQL

Oracle XML DB provides PL/SQL package DBMS_XDB to access Oracle XML DB repository programmatically from within PL/SQL code.

For example, to create a repository folder and then a resource in that folder, you might use the DBMS_XDB.createFolder and DBMS_XDB.createResource function respectively, as follows:

  1.  
  2. CONN xmlusr/xmlusr;
  3.    DECLARE
  4.    rslt BOOLEAN;
  5.    xmldoc VARCHAR2(250) :=
  6.    '<EMPLOYEE
  7.    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  8.    xsi:noNamespaceSchemaLocation="employee.xsd"
  9.    id="303">
  10.    <ENAME>Locke</ENAME>
  11.    <SALARY>7000</SALARY>
  12.    </EMPLOYEE>';
  13.    BEGIN
  14.    IF (NOT DBMS_XDB.existsResource('/public/xmlusr')) THEN
  15.       rslt:=DBMS_XDB.createFolder('/public/xmlusr');
  16.    END IF;
  17.    IF (NOT DBMS_XDB.existsResource('/public/xmlusr/emps')) THEN
  18.       rslt:=DBMS_XDB.createFolder('/public/xmlusr/emps');
  19.    END IF;
  20.    rslt := DBMS_XDB.createResource('/public/xmlusr/emps/emp303.xml',
  21.    xmldoc);
  22. COMMIT;
  23. END;
  24. /
 

As you can see, when creating a resource, regardless of whether it is a file or folder, you must specify an absolute path to that resource. This is required because, as in a conventional file system, each resource in the XML repository is identified by a path and name.


Trackback(0)
Comments (0)add comment

Write comment

busy
 
< Prev   Next >
Sponsored Links
© 2008 Exforsys.com
Joomla! is Free Software released under the GNU/GPL License.
Page copy protected against web site content infringement by Copyscape