c# - XML Serializer - Hide Element -


good afternoon,

i have following code:

public class purchaseorder {     public item [] items } public class item {     public string itemid     public decimal itemprice } 

when serialized, generates following xml:

<purchaseorder xmlns:xsi=http://www.w3.org/2001/xmlschema-instance xmlns:xsd="http://www.w3.org/2001/xmlschema">     **<items>**         <item>             <itemid>aaa111</itemid>             <itemprice>34.22</itemprice>         <item>         <item>             <itemid>bbb222</itemid>             <itemprice>2.89</itemprice>         <item>     **</items>** </purchaseorder> 

is there way of omitting <items> </items> element (in bold) - continue include <item> element?

if use list rather array, follows:

public class purchaseorder {     [xmlelement("item")]     public list<item> items; } public class item {     public string itemid;     public decimal itemprice; } 

will produce:

<purchaseorder xmlns:xsi=http://www.w3.org/2001/xmlschema-instance xmlns:xsd="http://www.w3.org/2001/xmlschema">     <item>         <itemid>aaa111</itemid>         <itemprice>34.22</itemprice>     <item>     <item>         <itemid>bbb222</itemid>         <itemprice>2.89</itemprice>     <item> </purchaseorder> 

Comments