Reputation: 4892
In the following composition please note the serialization attributes are lowercase and the array property in the root is serialized accordingly but its child element are not honoring this decoration.
I spected this:
<engine>
<servos>
<servo>
</servo>
</servos>
</engine>
But instead i get this:
<engine>
<servos>
<Servo> <!-- here is the problem-->
</Servo>
</servos>
</engine>
Code:
[XmlRoot( "engine" )]
public class Engine {
[XmlArray( "servos" )]
public List<Servo> Servos {
get { return servos; }
set { servos = value; }
}
}
[XmlRoot( "servo" )] //Child ignoring lowercase decoration
public class Servo {
}
What is the correct way to serialize as indicated by the attribute?
Upvotes: 0
Views: 631
Reputation: 3738
You have to add XmlArrayItem attribute to the Servos
property:
[XmlArrayItem( "servo" )]
[XmlArray("servos")]
public List<Servo> Servos {
get;
set ;
}
}
Upvotes: 3