Marcus
Marcus

Reputation: 3869

Extract the data from clob data type xml value

I have the following xml value which is stored in the request_xml column and which is clob data type:

  <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Body>
    <ns:updateRechargeTicketResponse xmlns:ns="http://service.soap.CDRator.com">
      <ns:return xmlns:ax232="http://core.result.service.soap.CDRator.com/xsd" xmlns:ax233="http://core.data.soap.CDRator.com/xsd" xmlns:ax230="http://payment.result.service.soap.CDRator.com/xsd" xmlns:ax228="http://data.soap.CDRator.com/xsd" xmlns:ax231="http://result.service.soap.CDRator.com/xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ax230:RechargeTicketResultDTO">
        <ax233:id xsi:nil="true"/>
        <ax232:code>0</ax232:code>
        <ax232:description>SOAP_GLOBAL_SUCCESS</ax232:description>
        <ax232:serviceUser xsi:nil="true"/>
        <ax232:success>true</ax232:success>
        <ax232:translationTag>SOAP_GLOBAL_SUCCESS</ax232:translationTag>
        <ax230:rechargeTicket xsi:type="ax228:RechargeTicketDTO">
          <ax233:id>201505131421267777</ax233:id>
          <ax233:billingGroupId>201505071857272816</ax233:billingGroupId>
          <ax233:code>BALANCE_DIRECTDEBIT</ax233:code>
          <ax233:dateCreated>2015-05-13</ax233:dateCreated>
          <ax233:dayOfMonth>0</ax233:dayOfMonth>
          <ax233:nextRechargeDate xsi:nil="true"/>
          <ax233:rechargeAmount>10.0</ax233:rechargeAmount>
        </ax230:rechargeTicket>
      </ns:return>
    </ns:updateRechargeTicketResponse>
  </soapenv:Body>
</soapenv:Envelope>

I want to extract the value from . I have used the below query but it returns nothing.I am getting an error as

ORA-19228: XPST0008 - undeclared identifier: prefix 'ax230' local-name 'ax230:rechargeTicket'
19228. 00000 -  "XPST0008 - undeclared identifier: prefix '%s' local-name '%s'"

Here is my query

   SELECT ID,CREATE_DATE,WEB_SERVICE_NAME,WEB_METHOD_NAME,xt_billingGroupId.BILLING_GROUP_ID,xt_error_code.ERROR_CODE,xt_error_message.ERROR_DESCRIPTION,xt_code.CODE,xt_rec_id.RECHARGE_TICKET_ID
FROM TEMP_SOAP_MONITORING_TOPUP sm
CROSS JOIN XMLTable(XMLNAMESPACES (
      'http://schemas.xmlsoap.org/soap/envelope/' AS "soapenv",
      'http://service.soap.CDRator.com' as "ns",
      'http://core.data.soap.CDRator.com/xsd' as "ax2130",
      'http://webshop.result.service.soap.CDRator.com/xsd' as "ax2147",
      'http://core.signup.data.soap.CDRator.com/xsd' as "ns3",
      'http://service.soap.CDRator.com' as "ns5",      
      'http://core.data.soap.CDRator.com/xsd' as "ax233",
      'http://core.result.service.soap.CDRator.com/xsd' as "ax232"
    ),
    'for $i in //*:billingGroupId return $i'
    passing XMLType(sm.REQUEST_XML)
    columns "BILLING_GROUP_ID" VARCHAR2(100) path '/') xt_billingGroupId    
CROSS JOIN XMLTable(XMLNAMESPACES (
      'http://core.result.service.soap.CDRator.com/xsd' as "ax232"
    ),
    'for $i in //ax232:code return $i'
    passing XMLType(sm.RESPONSE_XML)
    columns "ERROR_CODE" VARCHAR2(100) path '/') xt_error_code 
CROSS JOIN XMLTable(XMLNAMESPACES (
      'http://core.result.service.soap.CDRator.com/xsd' as "ax232"
    ),
    'for $i in //ax232:description return $i'
    passing XMLType(sm.RESPONSE_XML)
    columns "ERROR_DESCRIPTION" VARCHAR2(200) path '/') xt_error_message
CROSS JOIN XMLTable(XMLNAMESPACES (
      'http://core.result.service.soap.CDRator.com/xsd' as "ax232"
    ),
    'for $i in //*:code return $i'
    passing XMLType(sm.REQUEST_XML)
    columns "CODE" VARCHAR2(100) path '/') xt_code
CROSS JOIN XMLTable(XMLNAMESPACES (
      'http://core.data.soap.CDRator.com/xsd' as "ax233"
    ),
    'for $i in //ax230:rechargeTicket  return $i'
    passing XMLType(sm.RESPONSE_XML)
    columns "RECHARGE_TICKET_ID" VARCHAR2(200) path 'ax233:id') xt_rec_id

Upvotes: 2

Views: 1547

Answers (1)

Chris Cameron-Mills
Chris Cameron-Mills

Reputation: 4657

Your namespaces don't match on your source XML and your query

'http://data.soap.CDRator.com/xsd' as "ax233"

vs

xmlns:ax233="http://core.data.soap.CDRator.com/xsd"

Try either removing core. from your source or adding core. to your XMLNAMESPACES for ax233.


To fix the error:

ORA-19228: XPST0008 - undeclared identifier: prefix 'ax230' local-name 'ax230:rechargeTicket'
19228. 00000 -  "XPST0008 - undeclared identifier: prefix '%s' local-name '%s'"

you are missing namespace declaration for ax230 so to XMLNAMESPACES you need to add:

'http://payment.result.service.soap.CDRator.com/xsd' as "ax230",

You might also find it easier if the query is formatted nicer (unless you have a reason you are doing it the way you are). For a sample, see below:

SELECT 
  t.error_code
, t.error_description
, t.code
FROM temp_soap_monitoring_topup sm
, XMLTABLE(
    XMLNAMESPACES (
      'http://schemas.xmlsoap.org/soap/envelope/' AS "soapenv",
      'http://service.soap.CDRator.com' as "ns",
      'http://core.data.soap.CDRator.com/xsd' as "ax2130",
      'http://webshop.result.service.soap.CDRator.com/xsd' as "ax2147",
      'http://core.signup.data.soap.CDRator.com/xsd' as "ns3",
      'http://service.soap.CDRator.com' as "ns5",
      'http://payment.result.service.soap.CDRator.com/xsd' as "ax230",      
      'http://core.data.soap.CDRator.com/xsd' as "ax233",
      'http://core.result.service.soap.CDRator.com/xsd' as "ax232"
    )
  , 'soapenv:Envelope/soapenv:Body/ns:updateRechargeTicketResponse/ns:return'
  PASSING XMLTYPE(sm.response_xml)
  COLUMNS
    error_code        VARCHAR2(100) PATH 'ax232:code/text()'
  , error_description VARCHAR2(100) PATH 'ax232:description/text()'
  , code              VARCHAR2(100) PATH 'ax230:rechargeTicket/ax233:code/text()'
  ) t

Upvotes: 2

Related Questions