I have xml that part of structure looks like this:
<IDList>
<ValuesList ID="1">
<Value>1</Value>
<Value>2</Value>
<Value>3</Value>
</ValuesList>
<ValuesList ID="2">
<Value>1</Value>
<Value>2</Value>
<Value>3</Value>
</ValuesList>
</IDList>
What should be model classes for开发者_运维百科 xmlserializer, so I could deserialize it properly? On the level of IDList it's quite easy:
[XmlArray("IDList")]
[XmlArrayItem("ValuesList")]
public List<CValuesList> idList = new List<CValuesList>();
but how can I do it when the array element has extra xml attribute?
I tried to do ot in the way shown here:
http://www.codemeit.com/xml/c-xmlserializer-add-an-attribute-to-an-array-element.html
but it didn't worked for me. The elements of the array haven't been deserialized.
There is no simple way to do that.
A good solution would be to create an object that contains a list and your properties and inherit/implements IXmlSerializable.
I've seen some kind of quick and dirty way on this site: http://funcakes.posterous.com/adding-elements-to-lists-in-the-xmlserializer. Since the object doesn't inherit from ISerializable, it won't be serialized as a list by the serializer.
精彩评论