XPath无法通过SQL EXTRACTVALUE获得命名空间的XML?

时间:2019-04-25 15:05:36

标签: sql xml xpath soap

我正在尝试使用FaultMessage从XML响应中解析EXTRACTVALUE。下面是我的SQL代码:

SELECT EXTRACTVALUE( XMLTYPE('
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
    <s:Fault>
      <faultcode>s:Client</faultcode>
      <faultstring xml:lang="tr-TR">İstek şeması doğrulanamadı. Lütfen tüm bilgileri kontrol edin.</faultstring>
      <detail>
        <Fault xmlns="http://schemas.datacontract.org/2004/07/CustomServiceLibrary.DataContract" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
          <FaultCode>Schema_Customer_005|1e8c66-c333-4357-9c7d-3f4fcd553</FaultCode>
          <FaulCategory>Schema</FaulCategory>
          <FaultMessage> Customer name can not be blank, can not contain spaces, or any special characters. LASTNAMEFIRSTNAME is the required format. </FaultMessage>
          <FaultDetailedMessage>UMUT DEMIRCI</FaultDetailedMessage>
        </Fault>
      </detail>
    </s:Fault>
  </s:Body>
</s:Envelope>'),    
    '/s:Envelope/s:Body/s:Fault/detail/*:Fault/FaultMessage',
    'xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:a="http://schemas.datacontract.org/2004/07/CustomServiceLibrary.DataContract" ') a
FROM DUAL

请建议我如何获得FaultMessage

1 个答案:

答案 0 :(得分:2)

给出:

  1. 更深的Fault元素 及其后代 位于http://schemas.datacontract.org/2004/07/CustomServiceLibrary.DataContract命名空间中。
  2. 您似乎已经为a定义了http://schemas.datacontract.org/2004/07/CustomServiceLibrary.DataContract命名空间前缀
  3. 使用*作为名称空间前缀的通配符需要XPath 2.0 +。

更改

/s:Envelope/s:Body/s:Fault/detail/*:Fault/FaultMessage

/s:Envelope/s:Body/s:Fault/detail/a:Fault/a:FaultMessage

,以便您的XPath正确且不需要XPath 2.0+处理器。