输出XML数据表中UTF8而不是UTF16 [英] Output DataTable XML in UTF8 rather than UTF16

查看:205
本文介绍了输出XML数据表中UTF8而不是UTF16的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我创建使用.WriteXML(..)的XML文件的DataTable,虽然我与它在UTF-16编码输出和似乎有这个变化没有明显的方式有问题。据我所知,.NET使用UTF-16内部中的字符串,这是正确的?

I have a DataTable that I'm creating an XML file from using .WriteXML(..), although I have a problem with it exporting in UTF-16 encoding and there seems to be no apparent way of changing this. I understand that .NET uses UTF-16 internally within strings, is this correct?

我然后运行DataTable.WriteXML()产生通过XSLT的XML是包括在输出声明如下:

I'm then running the XML that DataTable.WriteXML() produces through an XSLT that includes the following in the output declaration:

<xsl:output method="xml" indent="yes" encoding="utf-8" />



但尽管如此,从转换输出为UTF16,和我想输入这个系统XML文件导入到不支持UTF16。

But still, the output from the transformation is in UTF16, and the system I am trying to input this XML file into doesn't support UTF16.

有没有办法将输出强制UTF-8?

Is there any way to force the output to UTF-8?

推荐答案

结果文档的编码是由<的编码属性决定; XSL:输出> 指令 - 不包含XSLT转换XML文档的XML声明

The encoding of the result-document is determined by the encoding attribute of the <xsl:output> instruction -- not by the XML declaration of the XML document that contains the XSLT transformation.

下面。有一个例子:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output encoding="utf-8"/>

 <xsl:template match="/">
   <t>Hello, world!</t>
 </xsl:template>
</xsl:stylesheet>



当任何XML文档(在这个简单的演示没有使用)应用,其结果通缉产生:<?/ p>

when applied on any XML document (not used in this simple demo), the result wanted is produced:

<?xml version="1.0" encoding="utf-8"?><t>Hello, world!</t>



待办事项:在.NET中,你可能需要指定特定的设置在的XmlWriter作为参数传递给 XslCompiledTransform.Transform()方法传递。请参阅 有关详细信息如何指定在 XmlWriterSettings 类想要的编码。

Do note: In .NET you might need to specify particular settings of the XmlWriter passed as parameter to the XslCompiledTransform.Transform() method. See this for details how to specify the wanted encoding in the XmlWriterSettings class.

这篇关于输出XML数据表中UTF8而不是UTF16的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆