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!

How to parce xml result using PL/SQL

jeffreehy-JavaNetNov 19 2015 — edited Nov 22 2015

Hi all.

I got an web service xml response, and I have to parseit using PL/SQL.

This is my XML:

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">

   <s:Header>

      <a:Action s:mustUnderstand="1">http://tempuri.org/IPagosLineaService/ProcesarComunicacionOnlineResponse</a:Action>

   </s:Header>

   <s:Body>

      <ProcesarComunicacionOnlineResponse xmlns="http://tempuri.org/">

         <ProcesarComunicacionOnlineResult xmlns:b="http://schemas.datacontract.org/2004/07/sige.Servicios.Sanaa" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">

            <b:REFGLOBAL>201510533758</b:REFGLOBAL>

            <b:IMPTOTAL>357.09</b:IMPTOTAL>

            <b:IMPMORA>0</b:IMPMORA>

            <b:TIPOIMP>67</b:TIPOIMP>

            <b:MONEDA>76</b:MONEDA>

            <b:FETPAG>2015-11-30T00:00:00</b:FETPAG>

            <b:CLIENTE>61998</b:CLIENTE>

            <b:NOMBRE>PINEDA MARIO ALFONSO</b:NOMBRE>

            <b:BANCO>7</b:BANCO>

            <b:CAJERO>1017</b:CAJERO>

            <b:BCID>B1234</b:BCID>

            <b:AVISOS>

               <b:AVISO>

                  <b:REFPAGO>201510533758</b:REFPAGO>

                  <b:TIPOAVISO>80</b:TIPOAVISO>

                  <b:IMPTOTAL>357.09</b:IMPTOTAL>

                  <b:IMPMORA>0.00</b:IMPMORA>

                  <b:IMPMIN>357.09</b:IMPMIN>

                  <b:TIPOIMP>67</b:TIPOIMP>

                  <b:MONEDA>76</b:MONEDA>

                  <b:CODIGO_COMERCIAL>2535510971</b:CODIGO_COMERCIAL>

                  <b:CLIENTE>61998</b:CLIENTE>

                  <b:NOMBRE>PINEDA MARIO ALFONSO</b:NOMBRE>

                  <b:DIRECCION>BL E RETORNO 7Y8 N7302 COL NUE</b:DIRECCION>

                  <b:RECIBOS>

                     <b:RECIBO>

                        <b:CODIGOFACT>201510533758</b:CODIGOFACT>

                        <b:FECHAFACT>2015-11-11T00:00:00</b:FECHAFACT>

                        <b:FECHAVTO>2015-11-30T00:00:00</b:FECHAVTO>

                        <b:IMPTOTAL>357.09</b:IMPTOTAL>

                        <b:IMPMORA>0.00</b:IMPMORA>

                        <b:TIPOIMP>67</b:TIPOIMP>

                        <b:MONEDA>76</b:MONEDA>

                        <b:EJERCICIO>2015</b:EJERCICIO>

                        <b:PERIODO>10</b:PERIODO>

                        <b:LECTANT>611</b:LECTANT>

                        <b:FECHLECTANT>2015-10-01T00:00:00</b:FECHLECTANT>

                        <b:LECTACT>728</b:LECTACT>

                        <b:FECHLECTACT>2015-11-02T00:00:00</b:FECHLECTACT>

                        <b:CONSUMO>31</b:CONSUMO>

                        <b:NUMSERIEAM>5884</b:NUMSERIEAM>

                        <b:CODIGO_COMERCIAL>2535510971</b:CODIGO_COMERCIAL>

                        <b:CATEGORIA>DOMESTICA</b:CATEGORIA>

                        <b:LINEAS_DETALLE>

                           <b:DETALLE>

                              <b:DESCRIPCION>Alcantarillado Sanitario</b:DESCRIPCION>

                              <b:CANTIDAD>31</b:CANTIDAD>

                              <b:UNIDMED>M3</b:UNIDMED>

                              <b:IMPORTE>57.12</b:IMPORTE>

                           </b:DETALLE>

                           <b:DETALLE>

                              <b:DESCRIPCION>Mantenimiento Medidor</b:DESCRIPCION>

                              <b:CANTIDAD>1</b:CANTIDAD>

                              <b:UNIDMED>M3</b:UNIDMED>

                              <b:IMPORTE>1.50</b:IMPORTE>

                           </b:DETALLE>

                           <b:DETALLE>

                              <b:DESCRIPCION>Costo fijo por Conexión</b:DESCRIPCION>

                              <b:CANTIDAD>1</b:CANTIDAD>

                              <b:UNIDMED>M3</b:UNIDMED>

                              <b:IMPORTE>70.00</b:IMPORTE>

                           </b:DETALLE>

                           <b:DETALLE>

                              <b:DESCRIPCION>Agua Potable</b:DESCRIPCION>

                              <b:CANTIDAD>31</b:CANTIDAD>

                              <b:UNIDMED>M3</b:UNIDMED>

                              <b:IMPORTE>228.47</b:IMPORTE>

                           </b:DETALLE>

                           <b:DETALLE>

                              <b:DESCRIPCION>Descuento Jubilado</b:DESCRIPCION>

                              <b:CANTIDAD>1</b:CANTIDAD>

                              <b:UNIDMED>M3</b:UNIDMED>

                              <b:IMPORTE>0.00</b:IMPORTE>

                           </b:DETALLE>

                           <b:DETALLE>

                              <b:DESCRIPCION>Intereses por Mora</b:DESCRIPCION>

                              <b:CANTIDAD>1</b:CANTIDAD>

                              <b:UNIDMED>M3</b:UNIDMED>

                              <b:IMPORTE>0.00</b:IMPORTE>

                           </b:DETALLE>

                           <b:DETALLE>

                              <b:DESCRIPCION>Saldo Pendiente</b:DESCRIPCION>

                              <b:CANTIDAD>1</b:CANTIDAD>

                              <b:UNIDMED>M3</b:UNIDMED>

                              <b:IMPORTE>0.00</b:IMPORTE>

                           </b:DETALLE>

                           <b:DETALLE>

                              <b:DESCRIPCION>Convenios</b:DESCRIPCION>

                              <b:CANTIDAD>1</b:CANTIDAD>

                              <b:UNIDMED>M3</b:UNIDMED>

                              <b:IMPORTE>0.00</b:IMPORTE>

                           </b:DETALLE>

                        </b:LINEAS_DETALLE>

                     </b:RECIBO>

                  </b:RECIBOS>

               </b:AVISO>

            </b:AVISOS>

         </ProcesarComunicacionOnlineResult>

      </ProcesarComunicacionOnlineResponse>

   </s:Body>

</s:Envelope>

This is my PL/SQL code:

create or replace

procedure          SANAA_CONSULTA(operacion in varchar2,

                                  codigocomercial in varchar2,

                                  banco      in varchar2,

                                  cajero      in varchar2,

                                  bcid      in varchar2,

                                  p_recordset          out sys_refcursor) as

  soap_request varchar2(32000);

  soap_respond clob; --VARCHAR2(32000);

  --soap_respond varchar2(30000);

  http_req     utl_http.req;

  http_resp    utl_http.resp;

  resp         XMLType;

  resp1        clob;

  --resp1        varchar2(30000);

  resp2        varchar2(30000);

  soap_err exception;

  v_code     varchar2(200);

  v_msg      varchar2(1800);

  v_len      number;

  v_txt      varchar2(32767);

  i          integer;

  tablaTemp  varchar2(2000);

  tablaTemp2 varchar2(2000);

  tablaTemp3 varchar2(2000);

  tablaTemp4 varchar2(2000);

  tablaTemp5 varchar2(2000);

  tablaTemp6 varchar2(2000);

  vCampo     clob;

  buffer     varchar2(32767);

begin

  soap_request := '<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/" xmlns:sige="http://schemas.datacontract.org/2004/07/sige.Servicios.Sanaa">' ||

   '<soap:Header/>' ||

   '<soap:Body>' ||

      '<tem:ProcesarComunicacionOnline>' ||

         '<!--Optional:-->' ||

         '<tem:msg>' ||

            '<!--Optional:-->' ||

            '<sige:OPERACION>' ||operacion||'</sige:OPERACION>' ||

             '<sige:CODIGO_COMERCIAL>' ||codigocomercial||'</sige:CODIGO_COMERCIAL>' ||

             '<sige:BANCO>' ||banco||'</sige:BANCO>' ||

            '<!--Optional:-->' ||

            '<sige:CAJERO>' ||cajero||'</sige:CAJERO>' ||

            '<!--Optional:-->' ||

            '<sige:BCID>' ||bcid||'</sige:BCID>' ||

         '</tem:msg>' ||

      '</tem:ProcesarComunicacionOnline>' ||

   '</soap:Body>' ||

'</soap:Envelope>';

  http_req     := utl_http.begin_request('http://181.210.29.198:8099/PagosLineaGGS/sige.servicios.sanaa.Pagoslineaservice.svc',

                                         'POST',

                                         'HTTP/1.1');

  utl_http.set_header(http_req, 'Content-Type', 'text/xml');

  utl_http.set_header(http_req, 'Content-Length', LENGTH(soap_request));

  utl_http.set_header(http_req,

                      'SOAPAction',

                      'http://tempuri.org/IPagosLineaService/ProcesarComunicacionOnline');

  utl_http.write_text(http_req, soap_request);

  http_resp := utl_http.get_response(http_req);

 

  DBMS_LOB.CREATETEMPORARY(vCampo, true);

  loop

    begin

      utl_http.read_text(http_resp, buffer, 32767);

      if buffer is not null

         and length(buffer) > 0

      then

        dbms_lob.writeappend(vCampo, length(buffer), buffer);

      end if;

    exception

      when others then

        exit;

    end;

  end loop;

 

 

 

  --utl_http.read_text(http_resp, soap_respond);

  utl_http.end_response(http_resp);

  --resp  := XMLType.createXML(soap_respond);

  --resp1 := resp.extract('/*').getStringVal();

  open p_recordset for

    with XML as

    (select XMLTYPE(vCampo) as OBJECT_VALUE from dual)

     --(select XMLTYPE(resp1) as OBJECT_VALUE from dual)

    --select

    --select *

    select descripcion,cantidad,unidmed,importe

   -- select *

      from XML,

           XMLTABLE(

           xmlnamespaces (

            'http://schemas.datacontract.org/2004/07/sige.Servicios.Sanaa' as "b"

          , 'http://www.w3.org/2003/05/soap-envelope/' as "s"

          , default 'http://tempuri.org/'

         )

        --'//b:DETALLE'

         --, '/ProcesarComunicacionOnlineResponse/ProcesarComunicacionOnlineResult/b:AVISOS/b:AVISO/b:RECIBOS/b:RECIBO/b:LINEAS_DETALLE/b:DETALLE'

         , '/s:Envelope/s:Body/ProcesarComunicacionOnlineResponse/ProcesarComunicacionOnlineResult/b:AVISOS/b:AVISO/b:RECIBOS/b:RECIBO/b:LINEAS_DETALLE/b:DETALLE'

         passing OBJECT_VALUE columns

                    descripcion varchar2(80) path 'DESCRIPCION',

                    cantidad varchar2(10) PATH 'CANTIDAD',

                    unidmed varchar2(10) PATH 'UNIDMED',

                    importe varchar2(2) PATH 'IMPORTE');

end SANAA_CONSULTA;

But I'm getting the following error:

ORA-31011: Fallo en el análisis de XML ORA-19202: Se ha producido un error en el procesamiento LPX-00229: input source is empty de XML ORA-06512: en "SYS.XMLTYPE", línea 272 ORA-06512: en línea 1

Can Anybody give me a solution?

Thank You in advance.

This post has been answered by BluShadow on Nov 20 2015
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 20 2015
Added on Nov 19 2015
4 comments
1,300 views