我在我的代码中关闭了BOM,它仍然将其打印在我的xml文档中。我不明白。我已经看着许多来源,仍然一无所获,应该只是new UTF8Encoding(false)仍然写入utf8 BOM
我的代码开始做这个工作一般
XDocument xmlDoc = XDocument.Load(CompDir + File.Name);
AppendToFile(xmlDoc, aDataRow);
using (var writer = new XmlTextWriter
(FilePrep.CompletedDirectory + File.Name, new UTF8Encoding(false)))
{
xmlDoc.Save(writer);
writer.Close();
}
break;
,并追加到文件看起来像这样
private void AppendToFile(XDocument xmlDoc, DataRow aDataRow)
{
//String StrName = aDataRow.ItemArray.GetValue(5).ToString() + ' ' + aDataRow.ItemArray.GetValue(6).ToString();
try
{
XElement foundEl = xmlDoc.Descendants("CreditScoreInfo").First();
foundEl.Add(new XElement("CreditScore", aDataRow.ItemArray.GetValue(2)),
new XElement("CreditScoreDt", aDataRow.ItemArray.GetValue(1)));
//,new XElement("ScoredName", StrName));
}
catch
{
XElement persPolicy = xmlDoc.Descendants("PersPolicy").First();
persPolicy.Add(new XElement("CreditScoreInfo",
new XElement("CreditScore", aDataRow.ItemArray.GetValue(2)),
new XElement("CreditScoreDt", aDataRow.ItemArray.GetValue(1))));
//,new XElement("ScoredName", StrName)));
}
}
您的代码保存XML似乎很好。请确保它是写入XML的唯一代码,以及用于验证第一个字节实际上是否正确显示文件的任何代码(即我认为VS可能无法以二进制模式正确地重新加载文件) –