次のコードで SaveOptions.DisableFormatting オプションを使用しているにもかかわらず:
XDocument xmlDoc = XDocument.Load(FileManager.SourceFile);
string element="campaign";
string attribute="id";
var items = from item in xmlDoc.Descendants(element)
select item;
foreach (XElement itemAttribute in items)
{
itemAttribute.SetAttributeValue(attribute, "it worked!");
//itemElement.SetElementValue("name", "Lord of the Rings Figures");
}
xmlDoc.Save(TargetFile, SaveOptions.DisableFormatting);
ターゲット XML ファイルには、これが追加されます。
<?xml version="1.0" encoding="utf-8"?>
元のフォーマットを保持し、バージョンとエンコーディング情報を追加しない方法はありますか?