在PLSQL中解析SOAP响应

时间:2018-11-17 07:25:59

标签: oracle soap plsql xmltype

我正在尝试解析plsql中的Java webservice返回的webservice SOAP响应。我没有遇到任何错误,但是我什么也没得到。下面是代码

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

我在这里做什么错了?

1 个答案:

答案 0 :(得分:0)

我可以在这里看到几个问题。...

1)您有两个名称空间(一个用于信封和正文,另一个用于节点),您需要在选择中考虑这两个名称空间

2)MyRet路径中的上下文来自信封,因此您需要指定完整路径或在开头使用//。

我对您实际想要的输出做出了一些假设,但我认为以下内容对您有用。

 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