怎么往文件里写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>