首页 新闻 会员 周边 捐助

输出XML文件怎么去掉BOM?

0
悬赏园豆:10 [已关闭问题] 关闭于 2014-08-13 21:24

怎么往文件里写XML去掉BOM啊?

我用下面这种方法,但是输出的XML有问题啊?

private static string GetXmlPhotoTemplate()
{
string strResult = string.Empty;
string resourceName = string.Format("{0}.{1}", MethodBase.GetCurrentMethod().DeclaringType.Namespace, "XmlPhotoTemplate.xml");

using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
{
if (stream != null)
{
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, buffer.Length);
strResult = Encoding.GetEncoding("utf-16").GetString(buffer);
}
}
return strResult;
}

 

 

static void Main(string[] args)
{
FileStream fs=new FileStream(@"c:\XmlPhotoTemplate.xml",FileMode.Truncate,FileAccess.ReadWrite);
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.ConformanceLevel = ConformanceLevel.Auto;
XmlWriter writer = XmlWriter.Create(fs, settings);
writer.WriteString(GetXmlPhotoTemplate());
writer.Close();
fs.Close();
Console.ReadLine();
}

 

怎么输出的XML有问题啊

<?xml version="1.0" encoding="utf-16"?>
<Media name="%filename%" propertyID="%eid%">
<Provider id="6"/>
<Subcategory id="%subcategoryid%"/>
<Rooms>
<Room id=""/>
<Room id=""/>
</Rooms>
<Activities>
<Activity type="Acquisition" application="SCORE" time="%timestamp%"/>
</Activities>
</Media>

吴顶天的主页 吴顶天 | 初学一级 | 园豆:39
提问于:2014-06-27 11:47
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册