Sponsored Links
PHP Oracle Tutorials
- PHP Oracle Web Development
- XML Processing in PHP and Oracle Applications
- Creating XML with the DOM PHP Extension
- Querying a DOM Document with XPath
- Transforming and Processing XML with XSLT
- Performing XML Processing inside the Database
- Moving All the XML Processing into the Database
- Performing XSLT Transformations inside the Database
- Using Oracle Database for Storing, Modifying, and Retrieving XML Data
- Using XMLType for Handling XML Data in the Database
- Using XML Schemas
- Retrieving XML Data
- Using XMLType Views
- Performing DML Operations on XML Schema Based XMLType Views
- Using Oracle XML DB Repository
- Accessing Repository Resources with SQL
- Taking Advantage of Standard Internet Protocols
- Querying Data with Oracle XQuery
- Breaking up XML into Relational Data
Tutorials
PHP OracleUsing XMLType for Handling XML Data in the Database
Using XMLType for Handling XML Data in the Database
Being an object type, XMLType can not only be used to store XML data in the database but also to operate on that data via its built-in methods. Regardless of the storage model you choose, XMLType provides a set of XML-specific methods to operate on XMLType instances.
The most commonly used methods of XMLType are listed in the following table:
| XMLType method | Description |
| existsNode | Checks whether the XML document in a given XMLType instance contains a node that matches the XPath expression passed as the parameter. If the specifi ed node is found, it returns 1; otherwise, it returns 0. |
| extract | Extracts a node or nodes from the XML document in an XMLType instance, based on the XPath expression passed as the parameter. Returns the result nodes as an XMLType instance. |
| createSchemaBasedXML | Explicitly associates an XML document in an XMLType instance with a registered XML schema specifi ed in the parameter. You might want to perform this operation when inserting an XML document into an XML schema-based XMLType column or table. |
| schemaValidate | Validates an XML document in an XMLType instance against an XML schema specifi ed in the parameter. On success, the status of the document is changed to VALIDATED; otherwise, an error is raised. |
| transform | Transforms an XML document in an XMLType instance with the XSL stylesheet specifi ed in the parameter. Returns the resultant document as an XMLType instance. |
You saw an example of using an XMLType method in the preceding sample application. In particular, in the DBServerXSLTrans.php script discussed in the Performing XSLT Transformations inside the Database section you use the getStringVal method of XMLType to retrieve the generated XHTML data as a VARCHAR value, so that it can then be loaded in a DOMDocument instance. If you recall, the query used in the DBServerXSLTrans.php script looks as follows:
- $query = 'SELECT XMLtransform(x.xmlcol,
- (SELECT stylesheet FROM XSLTstylesheets WHERE
- id = 1)).getStringVal()
- AS result FROM
- (SELECT XMLELEMENT("EMPLOYEES",
- XMLAgg(
- XMLELEMENT("EMPLOYEE",
- XMLATTRIBUTES(employee_id AS "id"),
- XMLFOREST(last_name AS "ENAME", salary AS "SALARY")
- )
- )
- ) AS xmlcol
- FROM hr.employees WHERE department_id=:deptid) x';
To see another XMLType method in action, namely transform, you might rewritethe above SQL statement as follows:
- $query = 'SELECT x.xmlcol.transform((SELECT stylesheet FROM
- XSLTstylesheets WHERE id = 1)).getStringVal()
- AS result FROM
- (SELECT XMLELEMENT("EMPLOYEES",
- XMLAgg(
- XMLELEMENT("EMPLOYEE",
- XMLATTRIBUTES(employee_id AS "id"),
- XMLFOREST(last_name AS "ENAME", salary AS "SALARY")
- )
- )
- ) AS xmlcol
- FROM hr.employees WHERE department_id=:deptid) x';
In the above query, you use the transform XMLType method as an alternative to the XMLtransform SQL function used in the original query. Since both transform and XMLtransform have the same functionality, the above queries will produce the same general result.
NOTE: XMLtransform is not the only example of an SQL function providing the same functionality as the appropriate XMLType method. In fact, Oracle XML DB provides analogous SQL functions for many XMLType methods. For example, XMLType methods extract and existsNode can be used instead of the SQL functions having the same names.
As you can see, the above queries operate on relational data, and transform it into XML format with SQL/XML generation functions. Before looking at the approaches you can take to retrieve XML data stored in the database natively, however, it would be a good idea to look at how you can create an XMLType storage in Oracle XML DB. The following section discusses how you can do this with the help of the XML Schema feature.
Comments
Sponsored Links
