XML
文件的列中获取值。我收到XML
个文件,该文件在我的函数中已分配给c_xml
,但出于此问题的目的,请在下面的代码中的变量c_xml
中表示。
问题是我没有在DBMS_OUTPUT中打印任何内容。 PUT_LINE,所以我无法从XML
文件中获取任何值,我无法继续进行开发。
如果有人可以帮助了解从XML
中提取值的问题,那会很棒。谢谢你的时间 :)
代码编写在Oracle PL / SQL上,如下:
DECLARE
c_xml xmltype;
BEGIN
c_xml :=
xmltype
('<?xml version=''1.0'' encoding=''utf-8''?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Header/>
<env:Body>
<srvc:returnActStateByEgnResponse xmlns="http://curr_state_egn/CURR_STATE_EGNService" xmlns:srvc="http://curr_state_egn/CURR_STATE_EGNServiceService">
<srvc:result>
<consents_tblType>
<item>
<req_id>112</req_id>
<purpose_code>CC0100</purpose_code>
<consent_state>0</consent_state>
</item>
<item>
<req_id>112</req_id>
<purpose_code>CC0200</purpose_code>
<consent_state>1</consent_state>
</item>
<item>
<req_id>112</req_id>
<purpose_code>CC0300</purpose_code>
<consent_state>0</consent_state>
</item>
</consents_tblType>
</srvc:result>
</srvc:returnActStateByEgnResponse>
</env:Body>
</env:Envelope>');
FOR consents_tblTypes IN
( SELECT
p_req_id
, p_purpose_code
, p_consent_state
FROM xmltable(
XMLNamespaces(
'http://schemas.xmlsoap.org/soap/envelope/' AS "env"
--, 'http://www.w3.org/2001/XMLSchema-instance' AS "xsi"
, 'http://curr_state_egn/CURR_STATE_EGNServiceService' AS "srvc"
),
'/env:Envelope/env:Body/srvc:returnActStateByEgnResponse/srvc:result/consents_tblType/item'
PASSING c_xml
COLUMNS
p_req_id NUMBER PATH 'req_id' --/text()
, p_purpose_code VARCHAR2(20) PATH 'purpose_code' --/text()
, p_consent_state NUMBER PATH 'consent_state' --/text()
)
)
LOOP
DBMS_OUTPUT.put_line('p_req_id = ' || to_char(consents_tblTypes.p_req_id)) ;
DBMS_OUTPUT.put_line('p_purpose_code = ' || consents_tblTypes.p_purpose_code) ;
DBMS_OUTPUT.put_line('p_consent_state = ' || to_char(consents_tblTypes.p_consent_state)) ;
END LOOP;
end;
答案 0 :(得分:1)
默认名称空间必须包含在声明中。
XMLNamespaces('http://schemas.xmlsoap.org/soap/envelope/' AS "env"
, 'http://curr_state_egn/CURR_STATE_EGNServiceService' AS "srvc"
, default 'http://curr_state_egn/CURR_STATE_EGNService')
此语句xmlns="http://curr_state_egn/CURR_STATE_EGNService"
更改了defult名称空间。