如何使用 XQuery/T-SQL 解析包含嵌套默认命名空间的客户 xml [英] How to use XQuery/T-SQL to parse customer xml that contains nested default namesapces

查看:35
本文介绍了如何使用 XQuery/T-SQL 解析包含嵌套默认命名空间的客户 xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一位客户使用我们开发的平台,该平台允许通过 MSSQL 中的存储过程解析客户 Web 服务返回的数据.我们有一个客户发回包含嵌套的 xmlns="xxxxxx" 声明的 xml,这些声明是针对不同 URI 位置的.首先这是有效的吗?其次,是否可以使用 XQuery 进行解析?我已经尝试使用 t-sql xml 数据类型的 .value 和 .query 功能来尝试解决这个问题,但第二个默认命名空间"发挥作用的点似乎是一个几乎不可能跨越的边界使用我所知道的技术.这是一个示例 xml 响应:

I have a customer using a platform we have developed that allows customer webservice return data to be parsed by a stored procedure in MSSQL. We have a customer sending xml back that contains nested xmlns="xxxxxx" declarations that are to different URI locations. First off is this valid? And secondly is it possible to parse using XQuery? I have tried using both .value and .query capabilities of the t-sql xml datatype to try to work through the issue but the point where the "second default namespace" comes into play seems to be a boundary that is nearly impossible to cross using techniques I am aware of. Here is a sample xml response:

    <?xml version="1.0" encoding="UTF-8"?>
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
     <soapenv:Body>
      <FF_LOG_RSPD_CONT xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/X.V1">
       <FF_LOGIN_WSDL_RSPD>
        <FF_PYIVR_RS_DER xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/Y.V1">
         <EMPLID>111111</EMPLID>
         <PIN>2222</PIN>
         <NEW_PIN_FLAG>N</NEW_PIN_FLAG>
         <REVOKE_FLAG>N</REVOKE_FLAG>
         <LAST_4_OF_SSN></LAST_4_OF_SSN>
         <WSDL_SUCCESS_FLAG>Y</WSDL_SUCCESS_FLAG>
        </FF_PYIVR_RS_DER>
       </FF_LOGIN_WSDL_RSPD>
      </FF_LOG_RSPD_CONT>
     </soapenv:Body>
    </soapenv:Envelope>

推荐答案

你能尝试显式调用命名空间吗?

Can you try explicitly calling out the namespaces?

declare @theXml XML = '<?xml version="1.0" encoding="UTF-8"?>
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
     <soapenv:Body>
      <FF_LOG_RSPD_CONT xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/X.V1">
       <FF_LOGIN_WSDL_RSPD>
        <FF_PYIVR_RS_DER xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/Y.V1">
         <EMPLID>111111</EMPLID>
         <PIN>2222</PIN>
         <NEW_PIN_FLAG>N</NEW_PIN_FLAG>
         <REVOKE_FLAG>N</REVOKE_FLAG>
         <LAST_4_OF_SSN></LAST_4_OF_SSN>
         <WSDL_SUCCESS_FLAG>Y</WSDL_SUCCESS_FLAG>
        </FF_PYIVR_RS_DER>
       </FF_LOGIN_WSDL_RSPD>
      </FF_LOG_RSPD_CONT>
     </soapenv:Body>
    </soapenv:Envelope>'

SELECT
    @theXml.value('
        declare namespace ns1="http://schemas.xmlsoap.org/soap/envelope/";
        declare namespace ns2="http://xmlns.oracle.com/Enterprise/Tools/schemas/X.V1";
        declare namespace ns3="http://xmlns.oracle.com/Enterprise/Tools/schemas/Y.V1";
        (/ns1:Envelope/ns1:Body/ns2:FF_LOG_RSPD_CONT/ns2:FF_LOGIN_WSDL_RSPD/ns3:FF_PYIVR_RS_DER/ns3:EMPLID)[1]', 
        'nvarchar(max)') as result

结果:

111111

这篇关于如何使用 XQuery/T-SQL 解析包含嵌套默认命名空间的客户 xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆