Search code examples
oracle-databasesoapplsqlxmltype

Parsing SOAP Response in PLSQL


I am trying to parse webservice SOAP response returned by a JAVA webservice in plsql. I am facing no error but i am getting nothing. Below is the code

WITH t as (select XMLTYPE('<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <ns2:helloResponse xmlns:ns2="http://example.com/">
         <ns2:return>Hello World</ns2:return>
      </ns2:helloResponse>
   </S:Body>
</S:Envelope>') as xml from dual)
  select * 
  from t,
        xmltable(XMLNAMESPACES('http://example.com/' as "ns2"),
                '/Envelope/Body'
                passing t.xml
                columns myret varchar2(50) path '/ns2:helloResponse/ns2:return'
        ) x

What am i doing wrong here ?


Solution

  • I can see a couple of issues here....

    1) You have two namespaces (one for the envelope and body, and the other for the nodes) you need to account for both of these in your select

    2) in your path for MyRet the context is from the envelope so you either need to specify the full path or use // at the beginning.

    I am making some assumptions as to the output that you actually want but I think the below should work for you.

     WITH t as (select XMLTYPE('<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
       <S:Body>
          <ns2:helloResponse xmlns:ns2="http://example.com/">
             <ns2:return>Hello World</ns2:return>
          </ns2:helloResponse>
       </S:Body>
    </S:Envelope>') as xml from dual)
      select * 
      from t,
            xmltable(XMLNAMESPACES('http://example.com/' as "ns2", 'http://schemas.xmlsoap.org/soap/envelope/' as "S"),
                    '/S:Envelope/S:Body'
                    passing t.xml
                    columns myret varchar2(50) path '//ns2:helloResponse/ns2:return'
            ) x