1

荷送人のフレームを取得するxmlファイルを受け取りました。次に、ソース xml のブロックを使用する回答 xml を生成します。そのため、xml のインスタンスである "consignor" 変数を別の xml インスタンスに挿入しようとしています。エラーはありませんが、値が挿入されません...何が問題なのですか?

DECLARE @source_vsd xml,
        @output_vsd xml


SELECT @source_vsd = N'<vd:vetDocument xmlns:vd="http://api.vetrf.ru/schema/cdm/mercury/vet-document/v2">
             <vd:certifiedConsignment xmlns:vd="http://api.vetrf.ru/schema/cdm/mercury/vet-document/v2">
                <vd:consignor xmlns:vd="http://api.vetrf.ru/schema/cdm/mercury/vet-document/v2">
                  <dt:businessEntity xmlns:dt="http://api.vetrf.ru/schema/cdm/dictionary/v2">
                    <bs:uuid  xmlns:bs="http://api.vetrf.ru/schema/cdm/base">04ceb142-053d-11e1-99b4-d8d385fbc9e8</bs:uuid>

                  </dt:businessEntity>
                </vd:consignor>
                <vd:consignee xmlns:vd="http://api.vetrf.ru/schema/cdm/mercury/vet-document/v2">
                  <dt:businessEntity xmlns:dt="http://api.vetrf.ru/schema/cdm/dictionary/v2">
                    <bs:uuid  xmlns:bs="http://api.vetrf.ru/schema/cdm/base">cbee869d-5405-4181-a1d8-7e8c8af4597b</bs:uuid>
                  </dt:businessEntity>
                </vd:consignee>
              </vd:certifiedConsignment>

            </vd:vetDocument>
            '
DECLARE @consignee xml,
        @consignor xml

DECLARE @t table(output_vsd_xml xml)  

;WITH XMLNAMESPACES( 'http://api.vetrf.ru/schema/cdm/mercury/g2b/applications/v2' as merc,
    'http://api.vetrf.ru/schema/cdm/mercury/vet-document/v2' as vd,
    'http://api.vetrf.ru/schema/cdm/dictionary/v2' as dt,
    'http://api.vetrf.ru/schema/cdm/base' as bs)
        SELECT
            @consignee = T.C.query('./vd:consignee[1]'),
            @consignor = T.C.query('./vd:consignor[1]')  
FROM   @source_vsd.nodes('/vd:vetDocument/vd:certifiedConsignment') T(C) 

DECLARE @szLocalTransactionId nvarchar(max),
        @szLogin nvarchar(max),
        @szDeliveryDate nvarchar(max)

SELECT @szLocalTransactionId = N'q1234',
        @szLogin = N'login',
        @szDeliveryDate = N'2015-09-28T17:17:00:00';

;WITH XMLNAMESPACES( 'http://api.vetrf.ru/schema/cdm/mercury/g2b/applications/v2' as merc,
                    'http://api.vetrf.ru/schema/cdm/mercury/vet-document/v2' as vd,
                    'http://api.vetrf.ru/schema/cdm/dictionary/v2' as dt,
                    'http://api.vetrf.ru/schema/cdm/base' as bs)
SELECT @output_vsd = (
SELECT  @szLocalTransactionId as 'merc:localTransactionId',
        (SELECT @szLogin as 'vd:login' FOR XML PATH ('merc:initiator'), ELEMENTS, TYPE),
        (SELECT @szDeliveryDate as 'vd:deliveryDate' FOR XML PATH ('merc:delivery'), ELEMENTS, TYPE)
FOR XML PATH ('merc:processIncomingConsignmentRequest')
)
SELECT @output_vsd as without_inserted_value

select @consignor as inserted_value

SET  @output_vsd.modify('
    declare namespace merc="http=api.vetrf.ru/schema/cdm/mercury/g2b/applications/v2";
    declare namespace vd="http=api.vetrf.ru/schema/cdm/mercury/vet-document/v2";
    declare namespace dt="http=api.vetrf.ru/schema/cdm/dictionary/v2";
    declare namespace bs="http=api.vetrf.ru/schema/cdm/base";
    insert sql:variable("@consignor") 
    into (/merc:processIncomingConsignmentRequest/merc:delivery/vd:deliveryDate)[1]')

SELECT @output_vsd as with_inserted_value
4

2 に答える 2

0

どうやら、XML 変数の更新にはいくつかの問題があります。値をテーブルに入れる (そして名前空間をwith namespaces()セクションに移動する) とすぐに、すべてが想定どおりに機能し始めるためです。

insert into @t (output_vsd_xml)
values (@output_vsd);

WITH XMLNAMESPACES (
    'http://api.vetrf.ru/schema/cdm/mercury/g2b/applications/v2' as merc,
    'http://api.vetrf.ru/schema/cdm/mercury/vet-document/v2' as vd,
    'http://api.vetrf.ru/schema/cdm/dictionary/v2' as dt,
    'http://api.vetrf.ru/schema/cdm/base' as bs
)
update t set output_vsd_xml.modify('
    insert sql:variable("@consignor")
    as first into /merc:processIncomingConsignmentRequest[1]/merc:delivery[1]/vd:deliveryDate[1]'
)
from @t t;

select * from @t;

テーブルは既にコードに含まれていましたが、未使用でした:)

于 2018-02-21T12:39:49.753 に答える