How to add the XML encoding tag

0

Adding the XML encoding clause

<?xml version="1.0" encoding="UTF-8"?>

When you generate the XML through FOR XML PATH as the following example:

SQL query:

   WITH XMLNAMESPACES (DEFAULT 'http:\www.oobj.com.br')
select
'1.0' as '@versao',
e.seq_nfe "idLote",
e.cnpj_forn "evento/infEvento/CNPJ",
e.chave_acesso "evento/infEvento/chNFE",
210200 "evento/infEvento/tpEvento",
1 "evento/infEvento/verEvento"

from
MOINHO.dbo.nfe_entrada e

where


e.seq_nfe = 15662


FOR XML PATH('envEventos'), Elements

Result:

<envEventos xmlns="http:\www.oobj.com.br" versao="1.0"><idLote>15662</idLote><evento><infEvento><CNPJ>25773037000183</CNPJ><chNFE>31170125773037000183550010000661601002373724</chNFE><tpEvento>210200</tpEvento><verEvento>1</verEvento></infEvento></evento></envEventos>
    
asked by anonymous 12.01.2018 / 18:49

1 answer

0

There was no need to report the XML declaration. Using the FOR XML PATH in SQL SERVER to generate the query result and the assembly that generated the XML file the way the integration system needed.

    
31.01.2018 / 16:28