在 PLSQL 中解析 SOAP 响应

Parsing SOAP Response in PLSQL

我正在尝试解析由 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) 您有两个命名空间(一个用于信封和正文,另一个用于节点),您需要在 select

中考虑这两个命名空间

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