c# - .net Serializing XML in a compact, human-readable way -
i'm serializing structure results in output:
<nachrichtenkonfiguration> <elemente> <element> <typ>bool</typ> <bezeichnung>gut</bezeichnung> </element> <element> <typ>int</typ> <bezeichnung>dauer</bezeichnung> </element> </elemente> <name>teiledaten</name> </nachrichtenkonfiguration>
and rather this:
<nachrichtenkonfiguration name="teiledaten"> <elemente> <element typ="bool" bezeichnung="gut"/> <element typ="int" bezeichnung="schleifdauer"/> </elemente> </nachrichtenkonfiguration>
is possible make xmlserialzer / xmlwriter (use attributes instead of nested elements)?
greetings,
tim
ok got it, need add [xmlattribute]-tag on corresponding declaration.
here's how. if have class called "person" , have 2 attributes in it, write code this:
[serializable] public class person { [xmlattribute] public int age; [xmlattribute] public string name; public person() { } }
when serializing (with xmlwriter settings set indent lines) above structure results in xml code:
<person age="21" name="stacky" />
Comments
Post a Comment