【问题标题】:Parsing SOAP XML response with XMLTABLE in DB2在 DB2 中使用 XMLTABLE 解析 SOAP XML 响应
【发布时间】:2021-12-28 15:10:38
【问题描述】:

我正在尝试使用 XMLTABLE 将 ResponseMSG 放入表中,但在解析 SAOP 响应时,PATH 出现了问题。错误是: SQL STATE 10506,代码 -16005
XPath 表达式引用具有静态上下文的未定义名称 soap
我不确定这里有什么问题。 XML 中没有命名空间,所以我认为路径
/soap:Envelope/soap:Body/SendFileResponse/SendFileResult 是正确的。

我正在使用的 SQL:

SELECT a.*
FROM XMLTABLE(
'$doc/soap:Envelope/soap:Body/SendFileResponse/SendFileResult' PASSING 
XMLPARSE(DOCUMENT systools.HTTPPOSTCLOB('https://someurl.asmx?op=SendFile',
                            '<httpHeader>
                                <header name ="content-type" value ="text/xml"/>
                             </httpHeader>',
                            GET_CLOB_FROM_FILE('/folder/file1.txt')))
as "doc"
COLUMNS
Value VARCHAR(128) PATH '/soap:Envelope/soap:Body/SendFileResponse/SendFileResult') as a with all;

来自 HTTPPOSTCLOB 的响应是:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
        <SendFileResponse xmlns="http://e-customs.com/">
            <SendFileResult>A file with the name file1.txt has already been uploaded.</SendFileResult>
        </SendFileResponse>
    </soap:Body>
</soap:Envelope>

具有 xml 的 file.txt 如下所示:

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <SendFile xmlns="http://test-url.com/">
      <EM>
        <Security>
          <CompanyName>aaa</CompanyName>
          <UserId>bbb</UserId>
          <CompanyPassword>ccc</CompanyPassword>
          <UserPassword>ddd</UserPassword>
        </Security>
        <Action>atNew</Action>
        <File>
          <Filename>string</Filename>
          <FileSize>12</FileSize>
          <FileContent>some content</FileContent>
          <FileType>ftCDS2Level</FileType>
          <ExtraInfo1>string</ExtraInfo1>
          <ExtraInfo2>string</ExtraInfo2>
          <ExtraInfo3>string</ExtraInfo3>
          <ExtraInfo4>string</ExtraInfo4>
          <ExtSysId>string</ExtSysId>
        </File>
      </EM>
    </SendFile>
  </soap12:Body>
</soap12:Envelope> 

【问题讨论】:

  • Web 服务响应有一个默认命名空间:xmlns="http://e-customs.com/"。您需要同时考虑 SendFileResponseSendFileResult 元素,
  • 我已经尝试使用 PATH '/soap:Envelope/soap:Body/*:SendFileResponse/*:SendFileResult ,但它仍然无法正常工作,或者在这种情况下我无法使用 '*:' ?
  • 我已将xmlnamespaces ('http://e-customs.com/' as "ec") 添加到 xmltable 并将 PATH 修改为:PATH '/soap:Envelope/soap:Body/ec:SendFileResponse/ec:SendFileResult',但我仍然收到相同的错误
  • 请编辑您的问题,并从相关 XML 响应中添加您的 SELECT ... 语句。
  • 我能够通过添加其余的命名空间来解决这个问题。我将在原始帖子中发布正确的 SQL。

标签: xml web-services soap db2 ibm-midrange


【解决方案1】:

我能够通过在 SELECT 中添加其余的命名空间来解决这个问题...

SELECT a.*
FROM XMLTABLE( xmlnamespaces ('http://e-customs.com/' as "ec",
    'http://www.w3.org/2003/05/soap-envelope' as "soap",
    'http://www.w3.org/2001/XMLSchema-instance' as "xsi",
    'http://www.w3.org/2001/XMLSchema' as "xsd"),
'$doc/soap:Envelope/soap:Body/ec:SendFileResponse/ec:SendFileResult' PASSING 
XMLPARSE(DOCUMENT systools.HTTPPOSTCLOB('https://uat.e-customs.descartes.com/webservices/ecustomsexchange.asmx?op=SendFile',
                            '<httpHeader>
                                <header name ="content-type" value ="text/xml"/>
                             </httpHeader>',
                            GET_CLOB_FROM_FILE('/General/emcsandnesfilesftp/new1.txt')))
as "doc"
COLUMNS
Value VARCHAR(128) PATH '/soap:Envelope/soap:Body/ec:SendFileResponse/ec:SendFileResult') as a with all;

现在它返回了我需要的东西。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-07
    • 2016-09-03
    • 1970-01-01
    相关资源
    最近更新 更多