Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


Share this Page URL
Help

CHAPTER 4 Parsing XML > DOM Parsing in SQL - Pg. 77

60 Oracle Database 11g: Building Oracle XML DB Applications DOM Parsing in SQL You don't really need to perform many DOM operations in Oracle Database 11g--when you create an XMLType object, you can process it using XMLType and XQuery functions. However, there are some operations where you might need to use DOM processing. Let's take a look at a few examples. Retrieving and Creating a CDATA Section This first example uses DBMS_XMLDOM (with alias XMLDOM) and DBMS_XMLPARSER (with alias XMLPARSER) to retrieve and create a new CDATA node (create_cdata.sql): Listing 4-3 Creating a CDATA Section in SQL declare l_xml clob; l_parser xmlparser.parser; l_domdocument xmldom.domdocument; l_domnode xmldom.domnode; l_domtnode xmldom.domnode; l_domfnode xmldom.domnode; l_domcnode xmldom.domnode; l_domnodelist xmldom.domnodelist; l_domcharactersection xmldom.DOMCDataSection; l_data varchar2(200); length NUMBER; begin l_xml := '<?xml version="1.0"?> <Test> <Data> <Height>1</Height> <Width>1</Width> <Length>1</Length> <Note><![CDATA[ One cubic unit of measure... ]]></Note> </Data> </Test>'; l_parser := xmlparser.newparser; xmlparser.parseclob(l_parser, l_xml); l_domdocument := xmlparser.getdocument(l_parser); xmlparser.freeparser(l_parser); l_domnode := xmldom.makenode(l_domdocument); l_domtnode := xslprocessor.selectsinglenode(l_domnode,'/Test/Data/Note'); xmldom.writetobuffer(l_domtnode,l_data); dbms_output.put_line('CDATA Node:'); dbms_output.put_line(l_data); -- Get CDATA Node