【发布时间】:2021-07-29 21:14:06
【问题描述】:
我对 XML 只是稍有了解。我需要解析来自 SOAP 请求的响应。通过大量搜索,我开发了以下查询来尝试提取状态。最终,我想从响应中获取状态、cntr 和 cntr_status 字段。我的查询没有错误,但也没有结果。我犯了什么菜鸟错误?
SELECT *
FROM XMLTABLE (
XMLNAMESPACES('http://schemas.xmlsoap.org/soap/envelope/' as "soapenv",
'http://www.w3.org/2001/XMLSchema' as "xsd",
'http://www.w3.org/2001/XMLSchema-instance' as "xsi",
'http://service.xxx.com/' AS "xxx"),
'/soapenv:Envelope/soapenv:Body/xxx:sendDataResponse/xxx:sendDataReturn/xxx:result'
PASSING XMLTYPE('<?xml version="1.0" encoding="UTF-8"?>' ||
'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" ' ||
' xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' ||
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' ||
' <soapenv:Body>' ||
' <sendDataResponse xmlns="http://service.xxx.com">' ||
' <sendDataReturn>' ||
' <result>' ||
' <build>Build 1</build>' ||
' <status>SUCCESS</status>' ||
' <cntr_statuses>' ||
' <cntr_result>' ||
' <cntr>1234567890A</cntr><cntr_status>SUCCESS</cntr_status>' ||
' </cntr_result>' ||
' <cntr_result>' ||
' <cntr>1234567890B</cntr><cntr_status>SUCCESS</cntr_status>' ||
' </cntr_result>' ||
' </cntr_statuses>' ||
' </result>' ||
' </sendDataReturn>' ||
' </sendDataResponse>' ||
' </soapenv:Body>' ||
'</soapenv:Envelope>')
COLUMNS status VARCHAR2(20) PATH 'xxx:status') xmlstuff ;
来自服务的示例响应被硬编码到 XMLTYPE 函数中。
我尝试了任意数量的涉及 xxx 命名空间的查询字符串和列路径,都没有产生任何结果。
可能有数百个 cntr 和 cntr_status 对。
感谢收看!
【问题讨论】:
-
您对 XML 格式有任何控制权并可以更改它,以便每个
cntr/cntr_status对都包含在不同的cntr_result元素中?尝试获取每个cntr元素,然后获取以下兄弟元素是一件痛苦的事情,如果包装元素中每个元素都只有一个单例,这会简单得多。 -
是的,对不起,我的错。我已经纠正了这个例子。这确实是结果返回给我的方式。
标签: sql xml oracle xml-namespaces oracle11gr2