XML-Enabled Applications - Part 4/Page 2 | WebReference

XML-Enabled Applications - Part 4/Page 2

[previous] [next]

XML-Enabled Applications - Part 4

Taking Advantage of Standard Internet Protocols

As mentioned, Oracle XML DB provides native support for standard internet protocols, such as HTTP(S), WebDAV, and FTP. Continuing with the preceding sample, you might, for example, upload another employee XML document into the XML repository with one of the above protocols, say, FTP.

[ Starting with Oracle Database 10g Release 2, FTP is disabled by default, for security reasons. This is achieved by setting the FTP port to 0. To enable FTP, you must manually set the FTP port number to an appropriate value, such as 2100, which is the default value in Oracle Database releases before 10g Release 2. Changing the FTP port to an appropriate value can be easily done with the help of Oracle Enterprise Manager, a graphical tool supplied with Oracle Database. For more information on Oracle Enterprise Manager, refer to Oracle documentation: chapter Getting Started with Oracle Enterprise Manager in the Oracle Database 2 Day DBA manual. ]

The uploadXML.php script shown below provides a simple example of how you might upload an XML document into the XML repository through FTP protocol.

In the above script, you start by setting up the parameters required to connect to the FTP server running on the database server.

By including the value of the employee's id attribute in the name of the XML file to be uploaded into the XML repository, you ensure the uniqueness of file names within the repository folder that contains employee XML documents in single files.

Then, you create a temp file and write XML content in it. Then, you connect to the Oracle FTP server and upload the file into the XML repository.

After the uploadXML.php script is executed, to make sure that the employee XML document has been successfully uploaded into the XML repository, you might issue the following query from SQL*Plus:

If everything is OK, this query should output the employee XML document uploaded by the uploadXML.php script:

So, after the uploadXML.php script is executed, the XML document inserted by the script becomes permanent immediately.

Handling Transactions

As you can see from the preceding example, changes made through internet protocols to repository resources become permanent once a single operation on a resource has been completed.

In contrast, all SQL and PL/SQL operations that you perform on the XML data stored in Oracle XML DB are transactional, irrespective of whether you're using XMLType storage or the XML repository. This allows you to combine SQL and PL/SQL statements operating on XML data within a logical unit of work and explicitly commit the transaction or roll it back if necessary.

Suppose you want to create a folder in the XML repository and then upload an XML document in it. The following code fragment shows how this can be done in PL/SQL:

The above PL/SQL code is transactional. If an error occurs during the execution of the createFolderfunction, then the results of execution of createFolder are discarded automatically.

On the other hand, when performing the same operations through FTP protocol, failure to create the resource doesn't affect the results of preceding operation. So, the following fragment of PHP code is not transactional:

[ Chapter 4 Transactions, presented earlier in this book, explains in detail how to use transactions in PHP/Oracle applications. ]

[previous] [next]