我在我的代码中关闭了 BOM,它仍然在我的 xml 文档中打印它。我不明白。我已经查看了许多来源,但仍然一无所获,应该从
我的代码是这样的
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)));
}
}