I have some XML that I am consuming and deserializing.
<Foo>
<Bars Baz="9">
<Bar>...</Bar>
<Bar>...</Bar>
</Bars>
</Foo>
Currently I deserialize it to this class:
[XmlRoot("Foo")]
public class Foo
{
public Foo() { }
[XmlArrayItem("Bar")]
public Bar[] Bars { get; set; }
}
This works fine, except that I don’t capture the value of @Baz. I want to add Baz as a property of Foo, but I’m not sure how. What attribute would I set on my Baz property to properly deserialize the xml?
[WhatAttributeGoesHere("?")]
public int Baz { get; set; }
Normally:
(with optional name, namespace, etc) is what you are after.
However, you can’t use that directly on a collection. You would need instead to have a wrapper class for Bars, with the attribute and a: