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!

convert clob to xmltype and then call extract function to get specific elem

854869Jun 15 2011 — edited Sep 13 2011
I have a need where Im getting output from a webservice using UTL_HTTP.HTML_PIECES which returns a PL/SQL-table of 2000-byte pieces of the data retrieved from the given webservice URL

The url returns an xml document which is more than 4000 characters long.

I need to parse it to get to a certain value.I have a working xpath and a select query in sqldeveloper that works when the same xml document
is loaded(manuall) into a database table


Now I append each 2000-byte data into a clob variable v_clob so that I would get the whole xml document in the v_clob variable




Problems Im facing

When I try to convert the clob to an xmltype object so that I can use the extract function I get the following error

ERROR at line 1:
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00209: PI names starting with XML are reserved
Error at line 1
ORA-06512: at "SYS.XMLTYPE", line 5
ORA-06512: at line 32


Question :
1: Is it possible that the space that Im appending to use the DBMS_LOB.append is causing this?
2: How do I go about this problem of concatenating the 2000 byte records that contain the xml
and then convert it to use the extract function?

Any help or suggestions are welcome.

code pasted below
Thanks for your help
rigel

===========================

DECLARE
l_pieces UTL_HTTP.HTML_PIECES;
-- We'll look at two 2000-byte pages at a time
l_two_pages VARCHAR2(4000);
l_start_read NUMBER;
l_end_read NUMBER;
l_quote VARCHAR2(12);
v_price VARCHAR2(1000):=NULL;
v_clob CLOB;
v_xmlfile SYS.XMLTYPE;
BEGIN
v_clob := NULL;
v_clob := ' '; -- add space so I can use the append method.-- maybe this is causing the createxml to fail??


l_pieces := UTL_HTTP.REQUEST_PIECES(('http://lt.gcom.vendor.com/opensearch/perform?q=itemno:1A123', 32);, 32);
FOR i IN 1 .. l_pieces.COUNT LOOP

l_two_pages :=l_pieces(i);
DBMS_LOB.append (v_clob,l_two_pages );

insert into xxdl_pm_clob_3(SUBJECT,BODY)--inserts each piece into a row.when i use the extract function by concat all the rows it works in sql developer
values(null,l_two_pages);
--inserts each piece into a row.when i use the select extract() from dual function by concat all the rows to get the whole xml doc it works in sqldeveloper

END LOOP;


SELECT SYS.XMLTYPE.createxml(v_clob) INTO V_XMLFILE from dual; -- this is where the error is being thrown I even tried the commented line below

--V_XMLFILE := SYS.XMLTYPE(v_clob);


/*
SELECT extract(V_XMLFILE,'/rss/channel/item/vendor:price/text()', 'xmlns:vendor="http://www.vendor.com/opensearchextensions/1.0"').getstringval()
into v_price from dual;
*/



DBMS_OUTPUT.put_line ('Price is ...');
DBMS_OUTPUT.put_line (v_price);


END;
/
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 11 2011
Added on Jun 15 2011
10 comments
45,735 views