How to add xml encoding <?xml version=“1.0” encoding=“UTF-8”?> to xml Output in SQL Server

后端 未结 4 1259
夕颜
夕颜 2020-11-28 15:59

Probably a duplicate of unanswered. SQL Server 2008 - Add XML Declaration to XML Output

Please let me know if this is possible. I read in some blogs

http://

4条回答
  •  盖世英雄少女心
    2020-11-28 16:06

    I have been working with this matter during the last days, and although there might be better solutions, I have ended up quite happy with this bash script:

    iconv -f UCS-2 -t UTF-8 products.xml > products_utf8.xml
    echo "\n\n$(cat products_utf8.xml)\n" > products_utf8_final.xml
    

    Basically, this script will get a file generated from the horrible bcp software, which generates incomplete and invalid XML data, convert it from the UCS-2 format to UTF-8 (first row), and add at the beginning and end of the file what it needs (second row of the script) to be valid and complete.

    It works for me. The script I used to generate the XML file with BCP is:

    bcp.exe "select * from dat1.dbo.Products FOR XML AUTO,ELEMENTS” queryout "C:\products.xml" -T -w -r -S .\SQLEXPRESS
    

提交回复
热议问题