Possible duplicate:
Removing Wrapper Elements from an XML Serialized Array
This is hard to explain, so I include an example of my problem. I have a parent class containing a list of child classes. When I serialize the parent, I get my child classes, but they are under the element with the name of the public property. An extra level is not what I need. I tried adding the XmlIgnore attribute to the property name, but it suppressed the entire property name and the collection of the invoices it contains.
Parent class:
[XmlRoot("header")] public class Lynx : INotifyPropertyChanged { #region /*-- Class Fields --*/ private List<InvoiceItem> _invoice = new List<InvoiceItem>(); #endregion [XmlArray("invoice")] [XmlArrayItem("invoice", typeof(InvoiceItem))] public List<InvoiceItem> invoice { get { return _invoice; } set { if (value != _invoice) { _invoice = value; OnPropertyChanged("invoice"); } } }
Child class:
[XmlType(TypeName = "invoice")] public class InvoiceItem : INotifyPropertyChanged { ... properties and methods of the class }
This is what it creates:
<header> <headerid>790aa61a-ad1b-49b9-bfb9-01fe3ca55eca</headerid> <invoice> <-- this line is not needed <invoice> <company>BRU111</company> <format>myformat</format> ...
This is what I need to build:
<header> <headerid>790aa61a-ad1b-49b9-bfb9-01fe3ca55eca</headerid> <invoice> <company>BRU111</company> <format>myformat</format> ...
source share