Skip to Main Content
  • Questions
  • How to Deserialize a HTTP POST RESPONSE

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, senthilkumar.

Asked: November 05, 2017 - 4:31 am UTC

Last updated: November 06, 2017 - 2:08 am UTC

Version: Oracle SQL DEvelope - 11G

Viewed 1000+ times

You Asked

I am getting a response for a request(l_value) as below:

<?xml version="1.0" encoding="utf-8"?>
<boolean xmlns=" http://tempuri.org/" >false</boolean>

How do I get the boolean value false and assign it to a variable lv_return
httpresp := UTL_HTTP.GET_RESPONSE(httpreq);
  
  BEGIN
    LOOP
      UTL_HTTP.READ_LINE(httpresp, l_value, TRUE);
      DBMS_OUTPUT.PUT_LINE(l_value);
    END LOOP;
    UTL_HTTP.END_RESPONSE(httpresp);
  EXCEPTION
  WHEN OTHERS THEN
    NULL;
  END;
  --return Status

RETURN lv_return;


and Connor said...

A bit of xmltype work will help out here

SQL> set serverout on
SQL> declare
  2    v varchar2(1000) := '<?xml version="1.0" encoding="utf-8"?><boolean xmlns="http://tempuri.org/">false</boolean>';
  3    x xmltype;
  4    c varchar2(20);
  5  begin
  6    x := xmltype(v);
  7    c := x.extract('boolean/text()','xmlns="http://tempuri.org/"').GETSTRINGVAL();
  8    dbms_output.put_line(c);
  9  end;
 10  /
false

PL/SQL procedure successfully completed.


So now that it is a string, all the normal PL/SQL rules can be used, eg

return c = 'true' ;

or to be more definitive

return case when c = 'true' then true when c = 'false' then false end;



Is this answer out of date? If it is, please let us know via a Comment

More to Explore

Design

New to good database design? Check out Chris Saxon's full fundamentals class.