我在代码中关闭了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)));
}
}