【发布时间】: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/"。您需要同时考虑 SendFileResponse 和 SendFileResult 元素, -
我已经尝试使用 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