Question

I am turning the BOM off in my code and it is still printing it in my xml document. I do not understand. I have looked into many sources and still nothing and should just start with

my code does this is general

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;

and the append to file looks like this

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)));
    }
}
Was it helpful?

Solution

Could you try this as an alternative way:

XmlWriterSettings settings = new XmlWriterSettings();
settings.Encoding = new UTF8Encoding(false);

using (XmlWriter writer = XmlWriter.Create(FilePrep.CompletedDirectory + File.Name, settings))
{
    xmlDoc.Save(writer);
    writer.Close();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top