How to add XML encoding tag

Asked

Viewed 363 times

0

How to add XML encoding clause

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

When you generate XML via FOR XML PATH as an example below:

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

Upshot:

<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>

1 answer

0

No need to inform the XML declaration. Using FOR XML PATH in SQL SERVER to generate the query result and Assembly that generated the XML file the way the integration system needed.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.