Hi i need help with the following in sql:
I need to create a xml file in this format
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:001.002.001.04">
<FIToFIPmtStsRpt>
<GrpHdr>
<MsgId></MsgId>
</GrpHdr>
<OrgnlGrpInfAndSts>
<OrgnlMsgId />
</OrgnlGrpInfAndSts>
</FIToFIPmtStsRpt>
</document>
at the moment i have a variable that holds the main info and i build up the between info (take it that grphdr can be inserted multiple times back into the main xml, with different info)
declare @xml xml='<Document
xmlns="urn:iso:std:iso:20022:tech:xsd:001.002.001.04">
<FIToFIPmtStsRpt>
</FIToFIPmtStsRpt>
</Document>
'
declare @xmlgrp xml='<GrpHdr>
<MsgId></MsgId>
</GrpHdr>'
--here i do some code to fill msgid
then when i add the grphdr back into the main xml
SET @xml.modify
('declare namespace a= "urn:iso:std:iso:20022:tech:xsd:001.002.001.04";
insert sql:variable("@xmlgrp")
into (a:Document/a:FIToFIPmtStsRpt)[1]')
select @xml
i need to get out the top file format but what happens now is the following is given
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:001.002.001.04">
<FIToFIPmtStsRpt>
<GrpHdr xmlns="">-- i need this xmlns tag out
<MsgId />
</GrpHdr>
</FIToFIPmtStsRpt>
</Document>
somehow i need the empty xmlns tag out of the xml. I can't convert to varchar(max) to remove as our db has limited the variable to 8000 characters and my xml can grow to more than 8000. There can be multiple grphdr or OrgnlGrpInfAndSts in 1 file
table: lim_Live_Inbound
lim_msg_id | lim_request_transaction_id | client_name
------------------------------------------------------
021/00210006/20160225/000002 | 00012016-02-25000000023 | Mr Piet
021/00210006/20160225/000002 | 00012016-02-25000000022 | Mrs Name
must generate like this
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:001.002.001.04">
<FIToFIPmtStsRpt>
<GrpHdr>
<MsgId>021/00210006/20160225/000002</MsgId>
</GrpHdr>
<OrgnlGrpInfAndSts>
<OrgnlMsgId>00012016-02-25000000023</OrgnlMsgId>
<name>Mr Piet</name>
</OrgnlGrpInfAndSts>
<OrgnlGrpInfAndSts>
<OrgnlMsgId>00012016-02-25000000022</OrgnlMsgId>
<name>Mrs Name</name>
</OrgnlGrpInfAndSts>
</FIToFIPmtStsRpt>
</document>
this is why i'm trying the insert into xml way. If any one can help me with a better way it would be much appreciated.