views:

81

answers:

1

Hi,

I think I already did that once upon a time, but I can't get it to work...

I've got a class that contains a variable

List<string> InputList;

When serialized, it's obviously like:

<InputList>
    <string>foo</string>
    <string>bar</string>
</InputList>

And, call me a control freak, but I want:

<InputList>
    <Input>foo</Input>
    <Input>bar</Input>
</InputList>

I think there's a kind of [metadata] info I can put above my variable to get that, but what's the syntax, please?

+1  A: 
[XmlArray("InputList")]
[XmlArrayItem(ElementName="Input")]
public List<string> InputList { get; set; }

Or if you just want the <Input> elements (no <InputList>)

[XmlElement("Input")]
public List<string> InputList { get; set; }
Marc Gravell
Thanks a lot, exactly what I wanted. I guess if I should ass a 'dear lazyweb' tag to this question ;o)
Vinzz