gpt4 book ai didi

xml - 使用 PL/SQL 解析 SOAP 响应

转载 作者:数据小太阳 更新时间:2023-10-29 03:00:36 26 4
gpt4 key购买 nike

我正在尝试使用以下代码解析 SOAP 响应,但我得到的是空响应。响应包含多个 namespace ,我认为这就是我遇到问题的地方。有人可以指出我做错了什么吗?

declare
l_xml xmltype;
begin
l_xml := xmltype.createXML('<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.cachelan.com/WebAPI/solarvuDataRetrieve.php" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns2="http://xml.apache.org/xml-soap" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:getDataResponse>
<return xsi:type="ns2:Map">
<item>
<key xsi:type="xsd:string">status</key>
<value xsi:type="xsd:int">0</value>
</item>
<item>
<key xsi:type="xsd:string">content</key>
<value xsi:type="xsd:string">"SolarVu OM Data Request"
"From Mar 1, 2017 To Mar 4, 2017"

"Timestamp","Date","Daily Energy(kWh)","Insolation(Wh/m^2)"
"1488344400","Mar 1/17","131.064","1,105.750"
"1488430800","Mar 2/17","370.576","3,202.750"
"1488517200","Mar 3/17","517.566","4,662.500"
"1488603600","Mar 4/17","382.626","6,001.750"
</value>
</item>
</return>
</ns1:getDataResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>');

for i in (SELECT t."key", t."value"
FROM dual d,
XMLTABLE(xmlnamespaces('http://www.w3.org/2001/XMLSchema-instance' as "xsi",
'http://schemas.xmlsoap.org/soap/envelope/' as "SOAP-ENV",
'http://www.cachelan.com/WebAPI/solarvuDataRetrieve.php' as "ns1",
'http://www.w3.org/2001/XMLSchema' as "xsd",
'http://xml.apache.org/xml-soap' as "ns2",
'http://schemas.xmlsoap.org/soap/encoding/' as "SOAP-ENC"),
'/getDataResponse/return/item[*]'
PASSING l_xml
COLUMNS
"key" varchar2(4000) PATH 'key',
"value" varchar2(4000) PATH 'value') t)
loop
dbms_output.put_line('Key is: '||i."key");
end loop;
end;
/

最佳答案

您没有在 getDataResponse 前面加上它在 XPath 中的命名空间,也没有包括信封和正文标签;所以将 XPath 更改为:

'/SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:getDataResponse/return/item'

只需更改您的代码即可生成:

Key is: status
Key is: content

PL/SQL procedure successfully completed.

关于xml - 使用 PL/SQL 解析 SOAP 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43218982/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com