我序列化導致該輸出的結構:.NET在一個緊湊的,易於理解的方式序列化XML
<NachrichtenKonfiguration>
<Elemente>
<Element>
<Typ>Bool</Typ>
<Bezeichnung>Gut</Bezeichnung>
</Element>
<Element>
<Typ>Int</Typ>
<Bezeichnung>Dauer</Bezeichnung>
</Element>
</Elemente>
<Name>Teiledaten</Name>
</NachrichtenKonfiguration>
,我想這是相當類似這樣的:
<NachrichtenKonfiguration Name="Teiledaten">
<Elemente>
<Element Typ="Bool" Bezeichnung="Gut"/>
<Element Typ="Int" Bezeichnung="Schleifdauer"/>
</Elemente>
</NachrichtenKonfiguration>
是否有可能使XmlSerialzer/XmlWriter做到這一點(使用屬性,而不是嵌套元素)?
問候,
添
是的,這是可能的。你有沒有嘗試過什麼? –
[如何將XmlDocument序列化爲格式良好的可讀XML?](http://stackoverflow.com/questions/17101817/how-to-serialize-an-xmldocument-to-a-well- formatted-human-readable-xml) –
@JayGould他不在尋找Identation。他正在尋找爲元素添加屬性的代碼,而不是元素的嵌套元素。 –