Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Parsing xml with namespaces

845805Mar 17 2011 — edited Mar 17 2011
Hi

I have to parse a xml file with 2 namespaces.

The file looks like as follows

<AA xmlns="http://XX.com/provider/C/D/E/F/2010/">
<BB xmlns="">
<Id>262</Id>
<Time>2011-03-10T13:55:00.000-06:00</Time>
<Indicator>true</Indicator>
</BB>
</AA>

i tried following 3 methods to parse this xml file but failed



PROCEDURE LOAD_XML
IS

l_clob := ' <<Above XML Content Here >>';
lv_root CONSTANT VARCHAR2(1000) := '/AA/BB'; /* Tried lv_root CONSTANT VARCHAR2(1000) := 'AA/BB' with all the three methods */
/* Method 1 */ lv_namespace constant varchar2(1000) := 'xmlns="http://XX.com/provider/C/D/E/F/2010/"';
/* Method 2 */ lv_namespace constant varchar2(1000) := 'xmlns="http://XX.com/provider/C/D/E/F/2010/" xmlns=""';
/*Method 3 */ lv_namespace constant varchar2(1000) := 'xmlns="http://XX.com/provider/C/D/E/F/2010/"/xmlns=""';
BEGIN
l_parser := dbms_xmlparser.newParser;
BEGIN

dbms_xmlparser.parseClob(l_parser, l_clob);
END;
l_doc := dbms_xmlparser.getDocument(l_parser);



-- Free resources associated with the CLOB and Parser now they are no longer needed.
dbms_xmlparser.freeParser(l_parser);

l_nl := dbms_xslprocessor.selectNodes(dbms_xmldom.makeNode(l_doc),lv_root,lv_namespaces );

FOR cur_rec IN 0 .. dbms_xmldom.getLength(l_nl) - 1 LOOP
l_n := dbms_xmldom.item(l_nl, cur_rec);
lv_rows_inserted_cnt := lv_rows_inserted_cnt + 1;
dbms_output.put_line('I am Here');

lv_rows_processed_cnt := lv_rows_inserted_cnt;
dbms_xmldom.freeDocument(l_doc);
l_clob := null;

dbms_output.put_line(lv_rows_processed_cnt||' Rows Parsed ');
END LOAD_XML ;


Every time zero rows are being parsed and it's not going into the for loop at all.
How to parse these kind of multiple namespaces (Especially default and unassigned namespaces ) ?

Thanks
Pramod
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 14 2011
Added on Mar 17 2011
5 comments
1,716 views