APEX_WEB_SERVICE.parse_xml 不返回具有嵌套命名空间的值

问题描述 投票:0回答:2

我正在使用 Oracle Autonomous 21c 并调用外部 SOAP Web 服务。使用 APEX_WEB_SERVICE.parse_xml 时,如果响应具有嵌套命名空间,则不会返回值。 我尝试了很多 p_xpath 和 p_ns 的组合,但没有成功。

set serveroutput on
declare 
l_envelope varchar2 (3000);
l_xml       XMLTYPE;
l_result    VARCHAR2(32767);
begin

l_xml := XMLTYPE('<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing"><env:Header><wsa:Action>http://xmlns.oracle.com/apps/cdm/foundation/parties/locationService/applicationModule//LocationService/createLocationResponse</wsa:Action><wsa:MessageID>urn:uuid:1273ab57-aace-4b2e-aa01-ec9c033699c5</wsa:MessageID></env:Header><env:Body><ns0:createLocationResponse xmlns:ns0="http://xmlns.oracle.com/apps/cdm/foundation/parties/locationService/applicationModule/types/"><ns2:result xmlns:ns2="http://xmlns.oracle.com/apps/cdm/foundation/parties/locationService/applicationModule/types/" xmlns:ns1="http://xmlns.oracle.com/apps/cdm/foundation/parties/locationService/" xmlns:ns4="http://xmlns.oracle.com/apps/cdm/foundation/parties/flex/location/" xmlns:ns3="http://xmlns.oracle.com/apps/cdm/foundation/parties/partyService/" xmlns:tns="http://xmlns.oracle.com/adf/svc/errors/" xmlns:ns0="http://xmlns.oracle.com/adf/svc/types/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns1:LocationResult"><ns1:Value><ns1:LocationId>300000003001817</ns1:LocationId><ns1:LastUpdateDate>2021-01-24T09:48:46.09Z</ns1:LastUpdateDate><ns1:LastUpdatedBy>Test_user2</ns1:LastUpdatedBy><ns1:CreationDate>2021-01-24T09:48:46.0Z</ns1:CreationDate><ns1:CreatedBy>Test_user2</ns1:CreatedBy><ns1:LastUpdateLogin>B6179371D2D5DABBE053F364310A5BB0</ns1:LastUpdateLogin><ns1:RequestId xsi:nil="true"/><ns1:OrigSystem xsi:nil="true"/><ns1:OrigSystemReference>300000003001817</ns1:OrigSystemReference><ns1:Country>EG</ns1:Country><ns1:Address1>Add Line 1</ns1:Address1><ns1:Address2 xsi:nil="true"/><ns1:Address3 xsi:nil="true"/><ns1:Address4 xsi:nil="true"/><ns1:City>Cairo</ns1:City><ns1:PostalCode>11451</ns1:PostalCode><ns1:State xsi:nil="true"/><ns1:Province xsi:nil="true"/><ns1:County xsi:nil="true"/><ns1:AddressStyle xsi:nil="true"/><ns1:ValidatedFlag>false</ns1:ValidatedFlag><ns1:AddressLinesPhonetic xsi:nil="true"/><ns1:PostalPlus4Code xsi:nil="true"/><ns1:Position xsi:nil="true"/><ns1:LocationDirections xsi:nil="true"/><ns1:AddressEffectiveDate xsi:nil="true"/><ns1:AddressExpirationDate xsi:nil="true"/><ns1:ClliCode xsi:nil="true"/><ns1:Language xsi:nil="true"/><ns1:ShortDescription xsi:nil="true"/><ns1:Description xsi:nil="true"/><ns1:SalesTaxGeocode xsi:nil="true"/><ns1:SalesTaxInsideCityLimits>1</ns1:SalesTaxInsideCityLimits><ns1:FaLocationId xsi:nil="true"/><ns1:ObjectVersionNumber>1</ns1:ObjectVersionNumber><ns1:CreatedByModule>HZ_WS</ns1:CreatedByModule><ns1:GeometryStatusCode>DIRTY</ns1:GeometryStatusCode><ns1:ValidationStatusCode xsi:nil="true"/><ns1:DateValidated xsi:nil="true"/><ns1:DoNotValidateFlag xsi:nil="true"/><ns1:Comments xsi:nil="true"/><ns1:HouseType xsi:nil="true"/><ns1:EffectiveDate>2021-01-24</ns1:EffectiveDate><ns1:AddrElementAttribute1 xsi:nil="true"/><ns1:AddrElementAttribute2 xsi:nil="true"/><ns1:AddrElementAttribute3 xsi:nil="true"/><ns1:AddrElementAttribute4 xsi:nil="true"/><ns1:AddrElementAttribute5 xsi:nil="true"/><ns1:Building xsi:nil="true"/><ns1:FloorNumber xsi:nil="true"/><ns1:StatusFlag>true</ns1:StatusFlag><ns1:InternalFlag>false</ns1:InternalFlag><ns1:TimezoneCode xsi:nil="true"/><ns1:Latitude xsi:nil="true"/><ns1:Longitude xsi:nil="true"/><ns1:Distance xsi:nil="true"/></ns1:Value></ns2:result></ns0:createLocationResponse></env:Body></env:Envelope>');


-- full path for the value to be extractd
--/env:Envelope/env:Body/ns0:createLocationResponse/ns2:result/ns1:Value/ns1:LocationId

l_result := APEX_WEB_SERVICE.parse_xml(
    p_xml   => l_xml,
--    p_xpath => '/env:Envelope/env:Body/ns0:createLocationResponse/ns2:result/ns1:Value/ns1:LocationId/text()'
    p_xpath => '//LocationId/text()'
    --,p_ns    => ' xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns0="http://xmlns.oracle.com/apps/cdm/foundation/parties/locationService/applicationModule/types/" xmlns:ns2="http://xmlns.oracle.com/apps/cdm/foundation/parties/locationService/applicationModule/types/"  xmlns:ns1="http://xmlns.oracle.com/apps/cdm/foundation/parties/locationService/"  xmlns:ns4="http://xmlns.oracle.com/apps/cdm/foundation/parties/flex/location/"  xmlns:ns3="http://xmlns.oracle.com/apps/cdm/foundation/parties/partyService/"  xmlns:tns="http://xmlns.oracle.com/adf/svc/errors/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:type="ns1:LocationResult"'
  );



DBMS_OUTPUT.put_line('');
DBMS_OUTPUT.put_line('l_result=' || l_result);

end;
/
--------------------
l_result=


PL/SQL procedure successfully completed.

我认为该问题是由于以下部分响应引起的:

<ns0:createLocationResponse xmlns:ns0="http://xmlns.oracle.com/apps/cdm/foundation/parties/locationService/applicationModule/types/">
            <ns2:result xmlns:ns2="http://xmlns.oracle.com/apps/cdm/foundation/parties/locationService/applicationModule/types/"
                        xmlns:ns1="http://xmlns.oracle.com/apps/cdm/foundation/parties/locationService/"
                        xmlns:ns4="http://xmlns.oracle.com/apps/cdm/foundation/parties/flex/location/"
                        xmlns:ns3="http://xmlns.oracle.com/apps/cdm/foundation/parties/partyService/"
                        xmlns:tns="http://xmlns.oracle.com/adf/svc/errors/"
                        xmlns:ns0="http://xmlns.oracle.com/adf/svc/types/"
                        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                        xsi:type="ns1:LocationResult">
        <ns1:Value>
                    <ns1:LocationId>300000003001817</ns1:LocationId>
                

任何提示表示赞赏 BR 汉尼

xml-parsing apex
2个回答
0
投票

在路径中使用命名空间可以,但并不理想:

l_result := 
  apex_web_service.parse_xml
  ( p_xml   => l_xml
  , p_xpath => '//ns1:Value/ns1:LocationId/text()'
  , p_ns    => 'xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns0="http://xmlns.oracle.com/apps/cdm/foundation/parties/locationService/applicationModule/types/" xmlns:ns2="http://xmlns.oracle.com/apps/cdm/foundation/parties/locationService/applicationModule/types/" xmlns:ns1="http://xmlns.oracle.com/apps/cdm/foundation/parties/locationService/"'
  );

-1
投票

尝试以下 xpath:

//*[contains(name(), "LocationId")]/text()
© www.soinside.com 2019 - 2024. All rights reserved.