2016-03-30 13 views
0

私はC#の簡単なツールをコーディングして、特定のXMLファイルの属性を変更しています。期待通りの変更を実行するためにenvolved すべてのコーディングが働いているが、それは私には、以下の問題が発生したファイルを保存するために来るとき、 ソースXMLファイルは、以下のような特定のidentがあります。保存した後C#特定のident設定をXmlWriterSettingsに設定する

<AAL2Bearer id="0" method="create"> 
<attributes> 
<pathId>16</pathId> 
<vccId>VCC/2</vccId></attributes></AAL2Bearer> 
<AAL2Bearer id="1" method="create"> 
<attributes> 
<pathId>8</pathId> 
<vccId>VCC/3</vccId></attributes></AAL2Bearer> 
<AAL2Bearer id="2" method="create"> 
<attributes> 
<pathId>1</pathId> 
<vccId>VCC/5</vccId></attributes></AAL2Bearer> 

私のXMLファイルをそれは:

<AAL2Bearer id="0" method="create"> 
<attributes> 
<pathId>16</pathId> 
<vccId>VCC/2</vccId> 
</attributes> 
</AAL2Bearer> 
<AAL2Bearer id="1" method="create"> 
<attributes> 
<pathId>8</pathId> 
<vccId>VCC/3</vccId> 
</attributes> 
</AAL2Bearer> 
<AAL2Bearer id="2" method="create"> 
<attributes> 
<pathId>1</pathId> 
<vccId>VCC/5</vccId> 
</attributes> 
</AAL2Bearer> 

私が試してみました:ノーIDENTのあるXMLファイルを持つことができるよこのスニペットでは

var settings = new XmlWriterSettings(); 
settings.Indent = true; 
settings.IndentChars = ""; 

しかし、私が必要としている各行の始まりです。同じ行のxmlノードを閉じる必要があります。基本的には新しいxmlノードに新しい行を追加するだけですが、XMLノードとその親を常に同じ行に閉じます。

おかげに関して

+0

パーサが文句を言わないノードが閉鎖され、その上にラインを気に

 var settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = ""; var outputEnc = new UTF8Encoding(false); settings.Encoding = outputEnc; using (var writer = XmlWriter.Create(targetXWO.FileName, settings)) { doc.Save(writer); } 

、なぜそれが重要ではない –

+0

それは私がアップロードしていますどこにとして問題ありませんこのタイプのidentが適用されていない場合、変更されたxmlはファイルを拒否します。 –

+0

あなたは正しいAlex Kです。それはBOMでした。私の間違いのために申し訳ありません:( –

答えて

1

質問して申し訳ありませんとアレックス・K.は正しかったです!

ファイルがBOMによって無効とマークされていました。 :(だけで解決

:?ありがとう

関連する問題