【问题标题】:Oracle's SOAP Msg with namespace extractValue() Function and XML NamespacesOracle 的带有命名空间 extractValue() 函数和 XML 命名空间的 SOAP 消息
【发布时间】:2015-06-22 13:21:38
【问题描述】:

我做错了什么? 我得到一个空洞的回应。 请帮忙看看下面的详细信息

下面我正在创建一个表并插入其中。 然后我从肥皂消息中提取 xpath 详细信息的值

CREATE TABLE REQUESTS (
    ID NUMBER(10,0) PRIMARY KEY,
    REQUEST XMLTYPE,
    RESPONSE XMLTYPE
);


INSERT INTO REQUESTS (ID, REQUEST, RESPONSE)
VALUES (
    2,  
     '<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:typ="http://xmlns.oracle.com/apps/prc/po/editDocument/purchaseOrderServiceV2/types/">
   <env:Header>
      <wsa:Action>http://xmlns.oracle.com/apps/prc/po/editDocument/purchaseOrderServiceV2//PurchaseOrderService/createPurchaseOrderResponse</wsa:Action>
      <wsa:MessageID>urn:uuid:04b70bff-5a77-4e24-a7a8-e5b217aa4b4a</wsa:MessageID>
   </env:Header>
   <env:Body>
      <ns0:createPurchaseOrderResponse xmlns:ns0="http://xmlns.oracle.com/apps/prc/po/editDocument/purchaseOrderServiceV2/types/">
         <ns1:result xsi:type="ns0:RequestResults" xmlns:ns1="http://xmlns.oracle.com/apps/prc/po/editDocument/purchaseOrderServiceV2/types/" xmlns:ns0="http://xmlns.oracle.com/apps/prc/po/editDocument/purchaseOrderServiceV2/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <ns0:POHeaderId>300000000694092</ns0:POHeaderId>
            <ns0:OrderNumber>27</ns0:OrderNumber>
            <ns0:SoldToLegalEntityId>300000000639014</ns0:SoldToLegalEntityId>
            <ns0:ChangeOrderNumber xsi:nil="true"/>
            <ns0:RequestStatus>SUCCESS</ns0:RequestStatus>
         </ns1:result>
      </ns0:createPurchaseOrderResponse>
   </env:Body>
</env:Envelope>', null);




   SELECT
    req.id,
    extractValue(
        req.request, 
    '/env:Envelope/env:Body/ns0:createPurchaseOrderResponse/ns1:result/ns0:OrderNumber',
         'xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns0="http://xmlns.oracle.com/apps/prc/po/editDocument/purchaseOrderServiceV2/types/" xmlns:ns1="http://xmlns.oracle.com/apps/prc/po/editDocument/purchaseOrderServiceV2/types/"  xmlns:ns0="http://xmlns.oracle.com/apps/prc/po/editDocument/purchaseOrderServiceV2/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ') Title
FROM 
    requests req
WHERE
    id = 2

【问题讨论】:

    标签: xml oracle xpath xml-namespaces


    【解决方案1】:

    查看extractValue() 的最后一个参数,它指定了命名空间前缀声明:

    'xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:ns0="http://xmlns.oracle.com/apps/prc/po/editDocument/purchaseOrderServiceV2/types/"
    xmlns:ns1="http://xmlns.oracle.com/apps/prc/po/editDocument/purchaseOrderServiceV2/types/" 
    xmlns:ns0="http://xmlns.oracle.com/apps/prc/po/editDocument/purchaseOrderServiceV2/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
    

    (为便于阅读添加了换行符)。

    命名空间前缀ns0被声明了两次,具有两个不同的命名空间URI值...其中一个与ns1共享!这遵循 XML 中的用法(这是可以理解的,但不是必需的),并且很难(或不可能?)确定在评估 XPath 表达式时 ns0 的哪个定义实际上有效。

    要修复它,请删除第一个 ns0 声明,因为 ".../types" 命名空间已被 ns1 覆盖。然后将您的 XPath 表达式更改为

    '/env:Envelope/env:Body/ns1:createPurchaseOrderResponse/ns1:result/ns0:OrderNumber'
    

    如果您知道命名空间声明的工作原理,您可以按照 XML 来了解为什么这样可以解决问题。如果不是,那么值得学习,如果您使用 XML 词汇表,如 SOAP,使用名称空间。尝试以下方法之一:

    您是否可以控制 XML 及其序列化方式?它在技术上没有任何问题,但命名空间前缀声明的选择似乎几乎旨在导致人为错误。如果您可以控制它,您应该选择助记符前缀并始终如一地使用它们,而不是像当前的 XML 那样更改它们。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多