问题的XDocument和BOM(字节顺序标记) [英] Issue with XDocument and the BOM (Byte Order Mark)

查看:158
本文介绍了问题的XDocument和BOM(字节顺序标记)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有什么办法可以输出一个XDocument未经BOM的内容是什么?当读取与Flash输出,它会导致错误。

Is there any way to output the contents of an XDocument without the BOM? When reading the output with Flash, it causes errors.

推荐答案

如果你正在编写XML用的XmlWriter,可以将编码设置为一个已经初始化离开了BOM。

If you're writing the XML with an XmlWriter, you can set the Encoding to one that has been initialized to leave out the BOM.

EG:System.Text.UTF8Encoding的构造函数接受一个布尔值,指定是否要在BOM,这样:

EG: System.Text.UTF8Encoding's constructor takes a boolean to specify whether you want the BOM, so:

XmlWriter writer = XmlWriter.Create("foo.xml");
writer.Settings.Encoding = new System.Text.UTF8Encoding(false);
myXDocument.WriteTo(writer);

会造成使用UTF-8编码,没有字节顺序标记的XmlWriter的。

Would create an XmlWriter with UTF-8 encoding and without the Byte Order Mark.

这篇关于问题的XDocument和BOM(字节顺序标记)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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